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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s