Get entire SharePoint farm webs inventory

function Get-DocInventory() {
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    foreach ($spService in $farm.Services) {
        if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
            continue;
        }

        foreach ($webApp in $spService.WebApplications) {
            if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }

            foreach ($site in $webApp.Sites) {
                foreach ($web in $site.AllWebs) {
                    foreach ($list in $web.Lists) {
                            $data = @{
                                "Web Application" = $webApp.ToString()
                                "Site" = $site.Url
                                "Web" = $web.Url
                                "list" = $list.Title
                                "Item Count" = $list.ItemCount
                        
                            }
                            New-Object PSObject -Property $data
                                                                                               
                       
                    }
                    $web.Dispose();
                }
                $site.Dispose()
            }
        }
    }
}
#Get-DocInventory | Out-GridView

Get-DocInventory | Export-Csv -NoTypeInformation -Path c:\SP_Inventory.csv

Comments

Popular posts from this blog

How to remove app from SharePoint 2013/2016

The model backing the context has changed since the database was created. Consider using Code First Migrations to update the database