Friday, April 14, 2017

Get all web applications, site collections and sites in a farm using powershell

You can get all web application and site collection in each web application and sub sites in each site collection in a SharePoint farm using the below powershell code

$webApp = Get-SPWebApplication
write-host $webApp
foreach ($webApps in $webApp)
{
write-host “WEBAPPLICATION :” $webApps.Name
foreach ($site in $webApps.Sites)
{


write-host “SITE: ” $site.URL
foreach($wb in $site.webs)
{
write-host "web: ” $wb.URL
}

}
}

save this as .ps1 extension and run the SharePoint management shell with administrator privilege and open the .ps1 file saved and you will get  list of web applications name and site collection in it and sub sites in that site collection one by one.

Happy Coding !!!