Saturday, September 27, 2014

Retrieve the List Item Count using PowerShell script


The following script will get the SharePoint List Item count for each list under each site collection. This script generated the output as CSV file.

Script:

cls
$ListsInfo = @()

$spsite= Get-SPSite -Limit All
foreach ($spsiteitem in $spsite)
{

$TotalItems = 0

ForEach ($Site in $spsiteitem.AllWebs)
{
    ForEach ($List in $Site.Lists)
    {
        $ListInfo=  New-Object System.Object
        $ListInfo | Add-Member -MemberType NoteProperty -Name "Site_Url" -Value $Site.Url -Force
        $ListInfo | Add-Member -MemberType NoteProperty -Name "List_Name" -Value $List.Title  -Force
        $ListInfo | Add-Member -MemberType NoteProperty -Name "Item_Count" -Value $List.ItemCount -Force
        $ListsInfo += $ListInfo
    }

}

$ListsInfo | Export-Csv -NoTypeInformation -Path "C:\ListData.csv"

}

No comments:

Post a Comment