#clear the PowerShell window
cls
#Set or reset default properties
$ReportPath = "SPSiteReport.csv"
$Result=""
$Count=0
#Load the PowerShell commandlets for SharePoint using PowerShell 1.0 and MOSS 2007 compatibility
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
#Print the header in the resulting file
$Header = " `tCount`tTitle`tURL`tType`tID`tParent"
Out-File -inputobject $Header -filepath $ReportPath -Force
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 )
{
#Get the count of items in the current list
$Count = $Count + ($List.Folders.Count + $List.Items.Count)
Write-Progress -activity "Inventorying items. . ." -status "Processing items in Site> $web - List> $list"
}
#Output the result of the current list
$Result = " " + "`t" + $Count + "`t" + $Web.Title + "`t" + $Web.URL + "`t" + $List.BaseType + "`t" + $web.ID + "`t" + $web.ParentWebID
Out-File -inputobject $Result -filepath $ReportPath -append
#Reset the item counter
$Count=0
}
}
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)