SharePoint Inventory

In this post I’ve sum up some power shell scripts for SharePoint Inventory, I will keep update this post with new PS scripts so that other admins benefits from this post.

Add-PSSnapin Microsoft.SharePoint.PowerShell
[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$web = Get-SPWeb "http://yourportaladdress"
$list = $web.Lists["NameOfList"]
$DeleteBeforeDate = [Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Now.AddDays(-10))
$caml='<Where> <Lt> <FieldRef Name="Created" /><Value Type="DateTime">{0}</Value> </Lt> </Where> ' -f $DeleteBeforeDate
$query=new-object Microsoft.SharePoint.SPQuery
$query.Query=$caml
$col=$list.GetItems($query)
Write-Host ("Total Item's created before 10 days is : {0}" -f  $col.Count)
$confirmation = Read-Host "Are you Sure You Want To Proceed (y/n):"
if ($confirmation -match "[yY]") {
  $col | % {$list.GetItemById($_.Id).Delete()}
}
$web.Dispose()