How to manage permissions of files in SharePoint sites using PowerShell? RRS feed

  • Question

  • I want to manage the permissions of files (tens of thousands in number) kept in different folders of a SharePoint site in my Office 365 admin account. How to achieve the same using PowerShell script.

    My SharePoint site URL is like https://xxxxx.sharepoint.com/sites/yyyyy

    I am trying to access https://xxxxx-admin.sharepoint.com/ using the real credentials.

    Actually, I am able to log in to the Office 365 account. But I do not know how to access folders and files inside the SharePoint sites and change their permissions. 

    Can anyone help to achieve this? Thanks.

    function Set-SPOListResetRoleInheritance
        param (
        $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
        $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
        $web = $ctx.Web
        $lists = $ctx.Web.Lists
        $webs = $ctx.Web.Webs
        Write-Host $ctx.Url -BackgroundColor White -ForegroundColor DarkGreen
        foreach( $ll in $lists)
                Write-Host "Restored inherited permissions for " $ll.Title
                Write-Host "Failed to restore permissions for " $ll.Title
        if($ctx.Web.Webs.Count -gt 0 -and $IncludeSubsites)
            for($i=0; $i -lt $ctx.Web.Webs.Count ; $i++)
                Set-SPOListResetRoleInheritance -Url ($ctx.Web.Webs[$i].Url) -Username $Username -AdminPassword $AdminPassword -IncludeSubsites $IncludeSubsites
    Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll"
    Set-SPOListResetRoleInheritance -Username "sai@xxxxxxxx.com" -Url "https://xxxxxxxx-admin.sharepoint.com" -AdminPassword "xxxxxxxx" -IncludeSubsites $true

    Friday, June 29, 2018 11:03 AM

All replies