Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created March 24, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/eb70dc6f1b6d4510c8eea630ef990ac3 to your computer and use it in GitHub Desktop.
Save vgrem/eb70dc6f1b6d4510c8eea630ef990ac3 to your computer and use it in GitHub Desktop.
Retrieve sub webs within a site collection
function Get-SPOWebs(){
param(
$Url = $(throw "Please provide a Site Collection Url"),
$Credential = $(throw "Please provide a Credentials")
)
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = $Credential
$web = $context.Web
$context.Load($web)
$context.Load($web.Webs)
$context.ExecuteQuery()
foreach($web in $web.Webs)
{
Get-SPOWebs -Url $web.Url -Credential $Credential
$web
}
}
@yvsuhas
Copy link

yvsuhas commented Oct 22, 2019

Hello Vadim,

How will you be able to get the count of all the subsites (all levels) and be able to export the information to CSV in the format (Site Coll URL | Subsite URL) using the recursive function call. I tried using a counter and returning it in the function but no luck. Please let me know if you can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment