Tìm kiếm trang web

SharePoint Online: Tìm tất cả các nhóm bảo mật Active Directory trong tuyển tập trang


Yêu cầu: Nhận tất cả các nhóm bảo mật AD trong trang web SharePoint Online.

PowerShell để tìm tất cả nhóm quảng cáo trong SharePoint Online:

Trong nhiều tổ chức, các nhóm Active Directory được sử dụng để quản lý quyền truy cập và quyền đối với các trang và nội dung SharePoint Online. Thông thường, các nhóm mới được tạo khi cần thiết và các nhóm cũ có thể không được sử dụng hoặc thậm chí bị lãng quên. Vì vậy, bạn có thể muốn tìm tất cả các nhóm AD trong hợp đồng thuê SharePoint Online của mình và xác định tư cách thành viên của họ nhằm mục đích khắc phục sự cố hoặc kiểm tra. May mắn thay, nhiệm vụ này có thể được thực hiện dễ dàng bằng PowerShell. Bài đăng trên blog này sẽ chỉ cho bạn cách sử dụng PowerShell để tìm tất cả các nhóm AD trong hợp đồng thuê SharePoint Online của bạn.

Đây là PowerShell để lấy tất cả các nhóm miền thư mục hoạt động từ tuyển tập trang SharePoint Online:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Set Variables for Site URL
$SiteURL= "https://crescent.sharepoint.com/sites/marketing/"
$ADGroupCollection= @()
 
#Setup Credentials to connect
$Cred = Get-Credential
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
    #Get all Users
    $Users=$Ctx.Web.SiteUsers
    $Ctx.Load($Users)
    $Ctx.ExecuteQuery()
 
    #Filter AD Groups from Users collection
    $ADGroups  = $Users | Where {$_.PrincipalType -eq "SecurityGroup"}

    #Get Each AD Group details
    Foreach($Group in $ADGroups)
    {
        #Get SharePoint Groups of the AD Group
        $Ctx.Load($Group.Groups)
        $Ctx.ExecuteQuery()
        $GroupNames = $Group.Groups | Select -ExpandProperty Title

        #Getting the members
        $ADGroup = new-object psobject
        $ADGroup | add-member noteproperty -name "AD Group Name" -value $Group.Title
        $ADGroup | add-member noteproperty -name "SP Group Membership" -value ($GroupNames -join "; ")
        #Add to Array
        $ADGroupCollection+=$ADGroup 
    }
    #Get the results
    $ADGroupCollection
}
Catch {
    write-host -f Red "Error getting AD Groups:" $_.Exception.Message
}

Nhận Nhóm Quảng cáo trong Tuyển tập Trang bằng cách sử dụng SharePoint Online Management Shell:

Lần này, hãy truy xuất các nhóm bảo mật AD với sự trợ giúp của trình quản lý SharePoint Online.


#Set Config Variables
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ADGroupCollection= @()

#Connect to SharePoint Online
Connect-SPOService -URL $AdminCenterURL

#Get All AD Security Groups from the site collection
$ADGroups = Get-SPOUser -Site $SiteUrl -Limit All | Where { $_.IsGroup -and $_.DisplayName -ne "Everyone" -and $_.DisplayName -ne "Everyone except external users" }
 
#Iterate through each AD Group
Foreach($Group in $ADGroups)
{
        #Send Data to an object array
        $ADGroup = new-object psobject
        $ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
        $ADGroup | add-member noteproperty -name "SharePoint Groups" -value ($Group.Groups -join ",")
        #Add to Array
        $ADGroupCollection+=$ADGroup          
}
#Get the Data
$ADGroupCollection

Đảm bảo bạn đã cài đặt SharePoint Online Management Shell trong máy khách trước khi thực thi tập lệnh.

Xuất nhóm Active Directory của tất cả tuyển tập trang bằng PowerShell:

Bây giờ, hãy sửa đổi tập lệnh trên một chút để trích xuất các nhóm AD từ tất cả các bộ sưu tập trang web trong đối tượng thuê và xuất chúng sang báo cáo CSV.


#Set Config Variables
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
$ADGroupCollection= @()
$ReportPath ="C:\Temp\ADGroups.csv"

#Connect to SharePoint Online
Connect-SPOService -URL $AdminCenterURL

#Get All Site Collections from the tenant
$Sites  = Get-SPOSite -Limit ALL

#Iterate through each site collection
ForEach($Site in $Sites)
{
    Write-host "Processing Site Collection:"$Site.URL -f Yellow

    #Get All AD Groups / Office 365 Groups from the site collection
    $ADGroups = Get-SPOUser -Site $Site.Url -Limit All | Where { $_.IsGroup -and $_.DisplayName -Notin ("Everyone","Everyone except external users", "Company Administrator", "SharePoint Service Administrator","All Users `(windows`)") }
 
    #Iterate through each AD Group
    Foreach($Group in $ADGroups)
    {
            #Send Data to an object array
            $ADGroup = new-object psobject
            $ADGroup | add-member noteproperty -name "Site Name" -value $Site.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 "SharePoint Groups" -value ($Group.Groups -join ",")
            #Add to Array
            $ADGroupCollection+=$ADGroup          
    }
}
#Export Data to CSV
$ADGroupCollection
$ADGroupCollection | export-csv $ReportPath -notypeinformation
Write-host "SharePoint Online Domain Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan

Đảm bảo rằng bạn có quyền đối với tất cả tuyển tập trang; nếu không, bạn có thể nhận được: “Quyền truy cập bị từ chối. Bạn không có quyền thực hiện hành động này hoặc truy cập tài nguyên này.” lỗi!

Tôi có thể tìm kiếm một Nhóm Quảng cáo cụ thể trên tất cả các trang web không? Chắc chắn rồi, chỉ cần thay đổi dòng # 18 thành:


$ADGroups = Get-SPOUser -Site $Site.Url -Limit All | Where { $_.IsGroup -and $_.DisplayName -ne "Everyone" -and $_.DisplayName -ne "Everyone except external users" -and $_.DisplayName -like '*ADSecurityGroupName*' }

PnP PowerShell để tìm tất cả các nhóm Active Directory và nhóm Office 365 trong SharePoint Online

Đây là phiên bản tập lệnh PnP PowerShell để trích xuất tất cả các Nhóm AD, bao gồm các nhóm Office 365 trong các trang SharePoint Online.


#Parameters
$AdminCenterUrl = "https://Crescent-admin.sharepoint.com"
$CSVPath = 'c:\Temp\ADGroupsInSPO.csv'

#Connect to SharePoint admin center
Connect-PnPOnline -Url $AdminCenterUrl -Interactive

#Get all SharePoint sites
$Sites = Get-PnPTenantSite
$Report = @()

#Loop through each site
ForEach ($Site in $Sites)
{
    Try {
        Write-host "Processing Site:"$Site.URL -f Yellow
        Connect-PnPOnline -Url $Site.Url -Interactive
        $ADGroups = Get-PnPUser | Where { $_.PrincipalType -eq "SecurityGroup" -and $_.Title -Notin ("Everyone","Everyone except external users", "Company Administrator", "SharePoint Service Administrator","All Users `(windows`)") }

        ForEach ($Group in $ADGroups)
        {
            $Report += New-Object Pscustomobject -Property @{
            SiteURL = $Site.URL
            GroupName = $Group.Title
            LoginName = $Group.LoginName
            GroupEmail = $Group.Email
            }
        }        
    }
    Catch {
        continue;
   }
}

$Report
 
#Generate a CSV file from the data
$Report | Export-Csv $CSVPath -NoTypeInformation

Tóm lại, bằng cách sử dụng tập lệnh PowerShell, quản trị viên có thể tìm thấy tất cả các nhóm bảo mật Active Directory được liên kết với tuyển tập trang SharePoint Online. Thông tin này có thể được sử dụng cho mục đích kiểm tra, thu hồi quyền truy cập của một nhóm người dùng hoặc cho các tác vụ quản trị khác. Tìm tất cả các nhóm bảo mật Active Directory trong tuyển tập trang SharePoint Online là một công cụ thiết yếu dành cho những quản trị viên muốn duy trì tính bảo mật và tính toàn vẹn của môi trường SharePoint của họ.

Bài viết liên quan