Month: July 2018
Posted by Harri Jaakkonen Posted on 23/07/2018 0 Comments on Sharepoint Online recursive permissions.
Posted in Office 365, Onedrive, Powershell, Sharepoint
Hi, When You migrate from a local fileshare, You will have a problem with recursive permissions from parent object. Here is script that can scan thru large library (5000+ items) and reset recursive permissions to them.
PowerShell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
function Restore-SPOListAllItemsInheritance { param ( [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, [Parameter(Mandatory=$true,Position=3)] [SecureString]$AdminPassword, [Parameter(Mandatory=$true,Position=4)] [string]$ListTitle ) $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) $ctx.Load($ctx.Web.Lists) $ctx.Load($ctx.Web) $ctx.Load($ctx.Web.Webs) $ctx.ExecuteQuery() $ll=$ctx.Web.Lists.GetByTitle($ListTitle) $ctx.Load($ll) $ctx.ExecuteQuery() ## View XML $qCommand = @" <View Scope="RecursiveAll"> <Query> <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy> </Query> <RowLimit Paged="TRUE">5000</RowLimit> </View> "@ ## Page Position $position = $null ## All Items $allItems = @() Do{ $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery $camlQuery.ListItemCollectionPosition = $position $camlQuery.ViewXml = $qCommand ## Executing the query $currentCollection = $ll.GetItems($camlQuery) $ctx.Load($currentCollection) $ctx.ExecuteQuery() ## Getting the position of the previous page $position = $currentCollection.ListItemCollectionPosition # Adding current collection to the allItems collection $allItems += $currentCollection Write-Host "Collecting items. Current number of items: " $allItems.Count } while($position -ne $null) Write-Host "Total number of items: " $allItems.Count for($j=0;$j -lt $allItems.Count ;$j++) { Write-Host "Resetting permissions for " $allItems[$j]["Title"] ".." $allItems[$j]["FileRef"] $allItems[$j].ResetRoleInheritance() $ctx.ExecuteQuery() } } # Paths to SDK. Please verify location on your computer. 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" #Enter the data $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="user@tenant.onmicrosoft.com" $Url="https://tenant.sharepoint.com" $ListTitle="library or list" Restore-SPOListAllItemsInheritance -Username $username -Url $Url -AdminPassword $AdminPassword -ListTitle $ListTitle |
Orginal source for…