How to obtain all sites within a URL?
-
05-02-2021 - |
Pregunta
Let's say i have this url:
http://mysharepoint.onprem.local/path1/path2/path3/path4
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?
Solución
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.