Guest User

Untitled

a guest
May 30th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. function Get-SPOFolderFiles
  2.  
  3. $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  4. $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
  5. $ctx.Load($ctx.Web)
  6. $ctx.ExecuteQuery()
  7.  
  8. Write-Host "Logged into Sharepoint"
  9. $ll=$ctx.Web.Lists.GetByTitle( $ListTitle)
  10. $ctx.Load($ll)
  11. $ctx.ExecuteQuery()
  12.  
  13. ## Page Position
  14. $page = $null
  15. ## All Items
  16.  
  17. #$spqQuery.ViewXml="<View Scope='FilesOnly'><RowLimit>1000</RowLimit></View>"
  18. $qCommand = @"
  19.  
  20. <OrderBy>
  21. <FieldRef Name='ID' Ascending='TRUE'/>
  22. </OrderBy>
  23.  
  24. Do{
  25. $spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
  26.  
  27. $spqQuery.ListItemCollectionPosition = $page
  28. #$spqQuery.ViewAttributes = "Scope='Recursive'";
  29. #$spqQuery.RowLimit = 100
  30. #$spqQuery.Query = $caml
  31.  
  32. $spqQuery.ViewXml = $qCommand
  33. $itemki=$ll.GetItems( $spqQuery)
  34. $ctx.Load($itemki)
  35. $ctx.ExecuteQuery()
  36.  
  37. ## Getting the position of the previous page
  38. $page = $itemki.ListItemCollectionPosition
  39.  
  40. Write-Host "################## PAGE " $page.PagingInfo " #########################"
  41. Write-Host "processing query results. Recs: " + $itemki.Count
  42.  
  43. $Counter = 0;
  44. foreach($item in $itemki)
  45. {
  46. $Counter++
  47.  
  48. Write-Host $Counter - $item["FileRef"] $item.ElementType
  49.  
  50. $file = $ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
  51. $ctx.Load($file)
  52. $ctx.Load($file.Versions)
  53.  
  54. $ctx.Load($file.ListItemAllFields)
  55. $Author=$file.Author
  56. $CheckedOutByUser=$file.CheckedOutByUser
  57. $LockedByUser=$file.LockedByUser
  58. $ModifiedBy=$file.ModifiedBy
  59. $ctx.Load($Author)
  60. $ctx.Load($CheckedOutByUser)
  61. $ctx.Load($LockedByUser)
  62. $ctx.Load($ModifiedBy)
  63.  
  64. #$ctx.Load($file.EffectiveInformationRightsManagementSettings)
  65.  
  66. #$ctx.Load($file.Properties)
  67. #$ctx.Load($file.VersionEvents)
  68.  
  69. try
  70. {
  71. $ctx.ExecuteQuery()
  72. }
  73. catch
  74. {}
  75.  
  76. if($CheckedOutByUser.LoginName -ne $null){
  77. Write-Host "File Name" $file.Name
  78. Write-Host "Checked out by" $CheckedOutByUser.LoginName
  79. $file.CheckIn('Checked in automatically', 'MajorCheckIn')
  80. $ctx.Load($file)
  81.  
  82. try
  83. {
  84. $ctx.ExecuteQuery()
  85. Write-Host $file.Name " has been checked in" -ForegroundColor DarkGreen
  86. }
  87. catch [Net.WebException]
  88. {
  89. Write-Host $_.Exception.ToString()
  90. }
  91.  
  92. }
  93.  
  94.  
  95.  
  96. }
  97. }
  98. Until($page -eq $null)
  99.  
  100. #Add required references to SharePoint client assembly to use CSOM
  101. #Enter the data
  102. $spPassword ="a password that is super duper secure"
  103. $secureStringPwd = ConvertTo-SecureString -string $spPassword –asplaintext –force
  104.  
  105. #$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
  106. $username="userUserton@aCompany.onmicrosoft.com"
  107. $Url="https://aCompany.sharepoint.com/DocManage/PDFRepo/"
  108. #$Url="https://aCompany.sharepoint.com/DocManage/TiffRepo/"
  109. $ListTitle="Documents"
Add Comment
Please, Sign In to add comment