Skip to content

Instantly share code, notes, and snippets.

@ITProCorner
Forked from chrisobriensp/IterateWebs.ps1
Created March 27, 2020 05:42
Show Gist options
  • Save ITProCorner/b0521c9f5420442f3a4c685dec273ca5 to your computer and use it in GitHub Desktop.
Save ITProCorner/b0521c9f5420442f3a4c685dec273ca5 to your computer and use it in GitHub Desktop.
PS + CSOM to iterate webs, starting from the ClientContext web..
. .\TopOfScript.ps1
$rootWeb = $clientContext.Web
$childWebs = $rootWeb.Webs
$clientContext.Load($rootWeb)
$clientContext.Load($childWebs)
$clientContext.ExecuteQuery()
function processWeb($web)
{
$lists = $web.Lists
$clientContext.Load($web)
$clientContext.ExecuteQuery()
Write-Host "Web URL is" $web.Url
}
foreach ($childWeb in $childWebs)
{
processWeb($childWeb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment