Guest User

Untitled

a guest
Mar 22nd, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. $url = 'https://domain.sharepoint.com/'
  2. $ListTitle = 'List Name'
  3. $folderName = 'Folder Name'
  4.  
  5. # Paths to SDK. Please verify location on your computer.
  6. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  7. Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  8.  
  9. # Login
  10. $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  11. $username = "myuser@domain.com"
  12. $AdminPassword = "my password"
  13. $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force
  14. $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
  15.  
  16. # Fetch list
  17. $ll=$ctx.Web.Lists.GetByTitle($ListTitle)
  18. $ctx.Load($ll)
  19. $ctx.ExecuteQuery()
  20.  
  21. # Find folder
  22. $folder = $ctx.Web.GetFolderByServerRelativeUrl($ctx.Web.ServerRelativeUrl + $listTitle + '/' + $folderName + '/')
  23. $ctx.Load($folder)
  24. $ctx.ExecuteQuery();
  25.  
  26. # Fetch items
  27. $spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
  28.  
  29. ## View XML
  30. $qCommand = @"
  31. <View Scope="RecursiveAll">
  32. <Query>
  33. <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
  34. </Query>
  35. <RowLimit Paged="TRUE">5000</RowLimit>
  36. </View>
  37. "@
  38. ## Page Position
  39. $position = $null
  40.  
  41. ## All Items
  42. $allItems = @()
  43. Do
  44. {
  45. $spQuery.ListItemCollectionPosition = $position
  46. $spQuery.ViewXml = $qCommand
  47. ## Executing the query
  48. $spQuery.FolderServerRelativeUrl = $folder.ServerRelativeUrl
  49. $itemki = $ll.GetItems($spQuery)
  50. $ctx.Load($itemki)
  51. $ctx.ExecuteQuery()
  52.  
  53. # Loop through all items
  54. $noOfObject = $itemki.Count
  55. for($j=0;$j -lt $itemki.Count ;$j++)
  56. {
  57. $itemki[$j].ResetRoleInheritance()
  58. if($j % 500 -eq 0) # Processing 500 items at a time.
  59. {
  60. $ctx.ExecuteQuery()
  61. }
  62. }
  63. $ctx.ExecuteQuery()
  64.  
  65. ## Getting the position of the previous page
  66. $position = $itemki.ListItemCollectionPosition
  67. Write-Host $position.PagingInfo $position.TypeId
  68.  
  69. # Adding current collection to the allItems collection
  70. $allItems += $itemki
  71. }
  72. # the position of the last page will be Null
  73. Until($position -eq $null)
Add Comment
Please, Sign In to add comment