Tập lệnh PowerShell để tìm tất cả các nhóm Active Directory trong SharePoint
Yêu cầu: Nhận danh sách Tất cả các nhóm Bảo mật AD được sử dụng trong trang SharePoint. Chúng tôi cần tạo báo cáo về các nhóm AD được sử dụng trong ứng dụng web SharePoint.
Tập lệnh PowerShell để tìm Nhóm AD trong SharePoint:
Đây là tập lệnh PowerShell của tôi để tìm và xuất các nhóm Active Directory trên tất cả các trang SharePoint trong ứng dụng web nhất định.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Change to your web application
$WebAppURL = "https://intranet.crescent.com"
#Get Web Application
$WebApp = Get-SPWebApplication $WebAppURL
#variable for data collection
$ADGroupCollection= @()
$ReportPath ="C:\ADGroups.csv"
foreach ($Site in $WebApp.Sites)
{
Write-host -foregroundcolor green "Processing Site Collection: "$site.RootWeb.URL
#Get all AD Security Groups from the site collection
$ADGroups = Get-SPUser -Web $Site.Url -Limit ALL | Where { $_.IsDomainGroup -and $_.displayName -ne "Everyone" }
#Iterate through each AD Group
ForEach($Group in $ADGroups)
{
Write-host "Found AD Group:" $Group.DisplayName
#Get Direct Permissions
$Permissions = $Group.Roles | Where { $_.Name -ne "Limited Access" } | Select -ExpandProperty Name
#Get SharePoint User Groups where the AD group is a member
$SiteGroups = $Group.Groups | Select -ExpandProperty Name
#Send Data to an object array
$ADGroup = new-object psobject
$ADGroup | add-member noteproperty -name "Site Collection" -value $Site.RootWeb.Title
$ADGroup | add-member noteproperty -name "URL" -value $Site.Url
$ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
$ADGroup | add-member noteproperty -name "Direct Permissions" -value ($Permissions -join ",")
$ADGroup | add-member noteproperty -name "SharePoint Groups" -value ($SiteGroups -join ",")
#Add to Array
$ADGroupCollection+=$ADGroup
}
}
#Export Data to CSV
$ADGroupCollection | export-csv $ReportPath -notypeinformation
Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan
Tập lệnh này tạo báo cáo tệp CSV có đầu ra:
- Tên tuyển tập trang và URL
- Tên nhóm Active Directory
- Quyền được áp dụng cho nhóm AD theo cấp độ quyền trực tiếp hoặc thông qua nhóm SharePoint.