Inventory Web App Using PowerShell

Ask: We need an Excel spreadsheet that will list out all the Sites, List, Libraries for a given Web App in SharePoint.

Found this post link, then modified it for my needs.

function Get-WebAppInventory($WebAppName) {
    [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 }
			if($webApp.name -eq $WebAppName)
			{
            foreach ($site in $webApp.Sites) {
                foreach ($web in $site.AllWebs) {
                        foreach ($list in $web.Lists) {
							$data = @{
								"Site" = $site.Url
                                "Web" = $web.Url
                                "list" = $list.Title
								"Type" = $list.BaseType	
								"Item Count" = $list.ItemCount
								"Last Item Modified" = $list.LastItemModifiedDate
							}
							
                            New-Object PSObject -Property $data
         
                    }
                }
            }
		}
        }
    }
}
#Get-WebAppInventory "SharePointed - name.sharepointed.com80" | Out-GridView
Get-WebAppInventory "SharePointed - name.sharepointed.com80" | Export-Csv -NoTypeInformation -Path c:\inventory2.csv

Above you have two options, Out-GridView or Export-CSV. You can use both or comment out one of the lines.

To get the parameter I’m passing to the function, you will need to look in Central Admin at your Web Apps list. Central Admin –> Application Management section –> Manage web applications. (_admin/WebApplicationList.aspx). In there, copy the name of the Web App.

You can modify the $data = @{ section to bring in other properties of the List.

Use PowerShell to Compare Two SharePoint Lists

What if, for some random reason you wanted to compare two SharePoint Lists or Libraries and find the differences.

For the setup, I created two Lists (A and B).  I then added a few items to the Lists. Notice, that List A has two extra items, 6 and 7.

     

 


$mSite = Get-SPweb "http://sharepointed.com/site/taco"
$aList = $mSite.lists["A"]
$bList = $mSite.lists["B"]

$arrA = @()
$arrB = @()

foreach($iA in $aList.Items)
{
 $arrA += $iA["Title"]
}

foreach($iB in $bList.Items)
{
 $arrB += $iB["Title"]
}

$c = Compare-Object -ReferenceObject $arrA -DifferenceObject $arrB -PassThru
Write-Host $c

Output of the above script is: 6 7

More about the Compare-Object cmdlet:

http://technet.microsoft.com/en-us/library/ee156812.aspx