Thu. Jun 16th, 2022
Function Break-InheritanceSubWebs($WebURL)
    #Set up the context
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($WebURL)
    Write-host "Connected to $WebURL" -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 "199 Error ! unable to break permissions for site - $($WebURL)" $_.Exception.Message

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