Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. cls
  2. function Recurse ($folder){
  3. write-host ----- $folder.Name
  4. $context.Load($folder.Subfolders)
  5. $context.ExecuteQuery()
  6. foreach($folder in $folder.Subfolders)
  7. {
  8. write-host ---------- $folder.Name
  9. }
  10.  
  11.  
  12. # write-host -------------- $folder.Subfolders
  13. }
  14. function GetChildFolders($RootFolder)
  15. {
  16. $context.Load($RootFolder)
  17. $context.Load($RootFolder.Folders)
  18. $context.ExecuteQuery()
  19. write-host $RootFolder.Name
  20. foreach($folder in $RootFolder.Folders)
  21. {
  22. if($folder.Name -ne "Forms")
  23. {
  24. Recurse -folder $folder
  25. }
  26. }
  27. }
  28.  
  29.  
  30. function Get-SPOWebs(){
  31. param(
  32. $Url = $(throw "Please provide a Site Collection Url"),
  33. $Credential = $(throw "Please provide a Credentials")
  34. )
  35.  
  36. $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  37. $context.Credentials = $Credential
  38. $web = $context.Web
  39. $context.Load($web)
  40. $context.Load($web.Webs)
  41. $context.ExecuteQuery()
  42. foreach($web in $web.Webs)
  43. {
  44.  
  45. Write-Host ""
  46. Write-Host ""
  47. Write-Host ------------- $web.Title -------------
  48. $lists = $web.lists
  49. $context.Load($lists)
  50. $context.ExecuteQuery()
  51. foreach ($list in $lists)
  52. {
  53. if($list.BaseType -eq "DocumentLibrary") {
  54. $list.RootFolder
  55. GetChildFolders -RootFolder $list.RootFolder
  56. }
  57.  
  58. }
  59. Get-SPOWebs -Url $web.Url -Credential $Credential
  60. $web
  61. }
  62. }
  63. $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
  64. $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
  65.  
  66.  
  67. $UserName = "User"
  68. $Password = "Pass"
  69. $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
  70. $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
  71.  
  72. $AllWebs = Get-SPOWebs -Url 'sharepointSiteURL'-Credential $SPOCredentials
  73.  
  74. function global:RecurseFolders([Microsoft.SharePoint.Client.Folder] $folderObject, $Context = $null, $tab = "")
  75. {
  76. if ($Context -eq $null)
  77. {
  78. Throw "The Context was Null and you MUST have a context to continue."
  79. }
  80. $Context.load($folderObject.folders)
  81. $Context.ExecuteQuery()
  82. write-host($tab+$folder.Name)
  83. $indent=" "
  84. $tab +=$indent
  85. foreach($folder in $folderObject.folders)
  86. {
  87. $Context.load($folder.files)
  88. $Context.ExecuteQuery()
  89. foreach ($file in $folder.files)
  90. {
  91. write-host($tab+"-F-"+$file.Name)
  92. }
  93. RecurseFolders -folderObject $folder -Context $Context -Tab $tab
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement