Iterate through all SharePoint web-applications, site-collections, websites from PowerShell

Iterate through all SharePoint web-applications, site-collections, websites from PowerShell
Please do not forget to comment if this helps.

PS :

$contentWebAppServices = (Get-SPFarm).services |  ? { $_.typename -eq "Microsoft SharePoint Foundation Web Application"}
foreach($webApp in $contentWebAppServices.WebApplications)
{
try
{
if ($webApp.Url -ne "If you want to skip something")
{
write-host "Starting WebApplications : " + $webApp.Url
foreach($siteColl in $webApp.Sites)
{
try
{

write-host "Starting SiteCollection : " + $siteColl.Url
$site = Get-SPSite $siteColl.Url
if ($site.Allwebs.Count -gt 0)
{
foreach($web in $site.Allwebs)
{
//Code for each web
}
}
}
catch [Exception]
{
write-host "Error in Code for : " $siteColl.Url
}
}
}
}
catch [Exception]
{
write-host "Error in Code for : " $siteColl.Url
}
}

Comments

Popular posts from this blog

Dataverse D365 REST Web Api using client secret From Postman or Power Automate desktop (PAD) .

Chrome Extension to auto refresh Power BI report.

How to call SharePoint online rest APIs using postman?