Let's say i have this url:


I need to be able to obtain all the sub-sites within the URL.

For example:

http://mysharepoint.onprem.local/path1/path2/path3/path4 is a site

http://mysharepoint.onprem.local/path1/path2/path3 is a site

http://mysharepoint.onprem.local/path1/path2 is not a site, just a context path.

http://mysharepoint.onprem.local/path1 is a site collection

Do I need to be able to back track through the url obtaining all the sub-sites? If so, given a URL, how can I determine if the URL is a sharepoint site or not?

Otherwise, what is a better way to do it?


You need create script where you are spliting url by "/" and trying to Get-SPSite or Get-SPWeb for each elements (gradually stocked) in Try/Catch statement if it's true you can work with it, if its false it will end in Catch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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