Created
July 31, 2020 08:15
-
-
Save OlafD/0c3bbc9c8c89541c1d36c0db9bfebad1 to your computer and use it in GitHub Desktop.
Loop all subwebs of a site collection (root site). Needs the PowerShell PnP extensions for SharePoint Online.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$Url, | |
$Credentials | |
) | |
function LoopWebs | |
{ | |
param ( | |
$WebCollection | |
) | |
foreach ($web in $WebCollection) | |
{ | |
$url = $web.Url | |
$subwebConnection = Connect-PnPOnline -Url $url -Credentials $Credentials -ReturnConnection | |
# do handling for this web | |
Write-Host $url | |
$web = Get-PnPWeb -Includes Webs -Connection $subwebConnection | |
LoopWebs -WebCollection $web.Webs | |
} | |
} | |
if ($Credentials -eq $null) | |
{ | |
$Credentials = Get-Credential | |
} | |
$rootConnection = Connect-PnPOnline -Url $Url -Credentials $Credentials -ReturnConnection | |
$web = Get-PnPWeb -Includes Webs -Connection $rootConnection | |
$url = $web.Url | |
# do handling for this web | |
Write-Host $url | |
LoopWebs -WebCollection $web.Webs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment