[Boolean]$IncludeStartWeb = $false

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all subsites for the provided site
$subsites = ((Get-SPWeb $StartWeb).Site).allwebs | ?{$_.url -like "$StartWeb*"}

foreach($subsite in $subsites)

Write-Host $subsite.Url


This will get the whole url like this http://sp2013/sub1/sub2 like this,

But i only want to get the url /sub1/sub2

When typing $subsite.Name it will only get /sub1 and not /sub2? How should I get /sub2 also?

1 Answer 1


Try $subsite.ServerRelativeUrl


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.