Inventory SharePoint Sites – PowerShell


Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

$SiteCollections = @()
$Data = Import-Csv -Path C:\Everything\SitesProfile.csv
if($Data)
{

    [string]$SiteUrls =""
    foreach($Site in $Data)
    {
         $SiteUrl = $Site.SiteUrl
         $sitecoll = New-Object Microsoft.SharePoint.SPSite($SiteUrl)   
         foreach ($web in $sitecoll.AllWebs) {
                    foreach ($list in $web.Lists) {
                        if ($list.Hidden) { continue }
                            $data = @{
                            "Site" = $sitecoll.Url
                            "Web" = $web.Url
                            "List" = $list.Title
                            "ItemCount" = $list.ItemCount
                            "LastModified" = $list.LastItemModifiedDate 
                            }
                            $List = New-Object PSObject -Property $data
                            $SiteCollections +=$List
                       
                            }
                    $web.Dispose();
                }
         $sitecoll.Dispose()
    }
}
#$SiteCollections | Out-GridView
#$SiteCollections | Export-Csv -NoTypeInformation -Path C:\Everything\Inventory.csv

Create Site Collection Inventory as CSV – PowerShell


Below listed PowerShell can get it done

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

$SiteCollections = @()
$Data = Import-Csv -Path E:\Tools\Everything\ErrorProfile.csv
if($Data)
{

    [string]$SiteUrls =""
    foreach($Site in $Data)
    {
         $SiteUrl = $Site.SiteUrl
         $sitecoll = New-Object Microsoft.SharePoint.SPSite($SiteUrl)   
         foreach ($web in $sitecoll.AllWebs) {
                    foreach ($list in $web.Lists) {
                        if ($list.Hidden) { continue }
                            $data = @{
                            "Site" = $sitecoll.Url
                            "Web" = $web.Url
                            "List" = $list.Title
                            "ItemCount" = $list.ItemCount
                            "LastModified" = $list.LastItemModifiedDate 
                            }
                            $List = New-Object PSObject -Property $data
                            $SiteCollections +=$List
                       
                            }
                    $web.Dispose();
                }
         $sitecoll.Dispose()
    }
}
$SiteCollections | Out-GridView
$SiteCollections | Export-Csv -NoTypeInformation -Path E:\Tools\Everything\Inventory.csv

Get Site Collection Size using PowerShell


Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
$Sites = (Get-SPContentDatabase Content_DB).Sites
$AllSites = @();
foreach($site in $Sites)
{
    $Site = Get-SPSite $site.Url
    $Size = $site.usage.storage
    $Size = $Size/1mb
    $ASite = New-Object PSObject
    Add-Member -input $ASite noteproperty 'Url' $Site.url
    Add-Member -input $ASite noteproperty 'Size' $Size
    $AllSites+=$ASite
    $site.Dispose()
}
$AllSites | Sort-Object descending  | Out-GridView