SharePoint Online: PowerShell Kullanarak Benzersiz İzinlere Sahip Tüm Alt Siteleri Bulun


Gereksinim: PowerShell kullanarak Benzersiz İzinlere Sahip Tüm SharePoint Çevrimiçi Sitelerini Bulun.

Bir sitenin (web) Benzersiz izinler kullanıp kullanmadığı veya izinleri üst öğeden devralıp devralmadığı nasıl kontrol edilir?

Bir SharePoint Çevrimiçi Alt Sitesinin benzersiz izinlere sahip olup olmadığını hızlı bir şekilde kontrol etmenin bir yolunu mu arıyorsunuz? PowerShell, benzersiz izinlere sahip tüm siteleri bulmayı çok kolaylaştırır! Bu blog yazısı, benzersiz izinlere sahip tüm alt siteleri bulmak için PowerShell'i nasıl kullanacağınızı gösterecektir.

Bir sitenin izinlerinin bozulup bozulmadığını kontrol etmek için şu adımları izleyin:

  1. Siteye gidin ve ardından Site Ayarları >> Site İzinleri >>Gelişmiş izinler ayarları'na gidin.
  2. “Gelişmiş izinler” sayfası sitenin benzersiz izinlere sahip olup olmadığı konusunda size bilgi verir. Sitenin benzersiz izinleri varsa
    "Bu sitenin benzersiz izinleri var" metnini alırsınız, aksi takdirde "Bu site, izinleri üst sitesinden devralır."

SharePoint Online: Tüm Web'leri (alt siteler) benzersiz izinlerle Almak için PowerShell

Bu PowerShell size bir site koleksiyonunun benzersiz izinler kullanan tüm alt sitelerini sunar:


#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"

#Define Parameter values
$SiteURL="https://crescent.sharepoint.com"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

Try {
    #Function to check if site has unique permissions
    Function Check-SPOWebUniquePermissions($SiteURL)
    {
        #Set up the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $credentials
 
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()

        #Check if the site has unique permissions
        $Web.Retrieve("HasUniqueRoleAssignments")
        $Ctx.ExecuteQuery()

        if ($Web.HasUniqueRoleAssignments -eq $true)
        {        
            Write-Host -f Green "Site '$($Web.URL)' has Unique Permissions"
        }
        else
        {
            Write-Host -f Yellow "Site '$($Web.URL)' is inhering Permissions from the Parent"
        }
 
        #Process Each subsite in current site
        ForEach($Web in $Web.Webs)
        {
            #call the function recursively
            Check-SPOWebUniquePermissions $Web.Url
        }
    } 
    #call the function 
    Check-SPOWebUniquePermissions $SiteURL
}
Catch {
    write-host -f Red "Error Checking Unique Permissions!" $_.Exception.Message
}

PnP PowerShell Benzersiz İzinlere Sahip Alt Siteler Alacak

PnP PowerShell'in yardımıyla tüm alt sitelerin benzersiz izin durumunu denetleyelim:


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive

    #Get All subsites from the SharePoint Online site collection
    $WebsCollection = Get-PnPSubWeb -Recurse -Includes HasUniqueRoleAssignments
    
    #Get Unique Permission status of each subsite
    $WebsCollection | Select Title, URL, HasUniqueRoleAssignments
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

İlgili makaleler