SharePoint PNP Get Sub Sites in Site Collection

The script below will provide you list of sites in Site collection using SharePoint PNP PowerShell

$Creds = Get-Credential
$SiteUrl = ""
Connect-PnPOnline -Url $SiteUrl -Credentials $Creds
$Site = Get-PnPSite
$Web = Get-PnPWeb

function GetSubWebs($Web, $Context)
    foreach($aWeb in $sweb.Webs)
        if($aWeb.Webs.Count > 0)
            GetSubWebs $aWeb $Context

$Context= Get-PnPContext
$webs= $Web.Webs
foreach($sweb in $webs)
    GetSubWebs $sweb $Context

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s