Wed. Jun 8th, 2022
Function BreakSiteInheritance([String]$SiteURL,$Credentials,$reportYN)
        $Timestamp = GetTimeStamp
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        Write-host "Connected to $SiteURL" -ForegroundColor Green
        $ctx.Credentials = $credentials;

        $Web = $ctx.Web
        Invoke-LoadMethod -Object $web -PropertyName "HasUniqueRoleAssignments"

        if ($web.HasUniqueRoleAssignments)
            write-host -f yellow "$($web.title) has unique permissions"
            write-host -f red "$($web.title) does not have unique permissions"
            #Break Permission inheritance of the Web - use existing groups from parent
            $Web.BreakRoleInheritance($True, $False)
            write-host -f yellow "Permission Broken for site $($SiteURL)"

        #Iterate through each subsite in the current web
        foreach ($Subweb in $web.Webs)
                #Call the function recursively to process all subsites underneaththe current web
        write-host -f Red "Error ! unable to break permissions for site - $($SiteURL)" $_.Exception.Message

This website uses cookies. By continuing to use this site, you accept our use of cookies.