Advertisement
PtiTom

SharePoint Scan subWebs

Aug 23rd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Script variables
  2. $targetWebUrl = "https://XXX.sharepoint.com"
  3. $login = "XXX@XXX.fr"
  4.  
  5.  
  6. function GetSubWebs($ctx, $web)
  7. {
  8.     $allWebs = $web.Webs
  9.     $ctx.Load($allWebs)
  10.     $ctx.ExecuteQuery()
  11.  
  12.     foreach($w in $allWebs)
  13.     {
  14.         $t = $w.Title
  15.         $u = $w.Url
  16.         "$t`t$u"
  17.  
  18.         GetSubWebs $ctx $w
  19.     }
  20. }
  21.  
  22.  
  23.  
  24. cls
  25. $scriptFolder = "XXX"
  26. Set-Location $scriptFolder
  27.  
  28. Import-Module "../Microsoft.SharePoint.Client.dll"
  29. Import-Module "../Microsoft.SharePoint.Client.Runtime.dll"
  30.  
  31. # SharePoint online credentials
  32. $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString
  33. $myCred = New-Object "Microsoft.SharePoint.Client.SharePointOnlineCredentials" -ArgumentList @($login, $SecurePassword)
  34.  
  35. $ctx = New-Object "Microsoft.SharePoint.Client.ClientContext" -ArgumentList @($targetWebUrl)
  36. $ctx.Credentials = $myCred;
  37.  
  38. $web = $ctx.Web #.AllWebs
  39. $ctx.Load($web)
  40. $ctx.ExecuteQuery()
  41.  
  42. $t = $web.Title
  43. $u = $web.Url
  44. "$t`t$u"
  45.  
  46. GetSubWebs $ctx $web
  47.  
  48. $ctx.Dispose()
  49.  
  50. "===== END ====="
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement