Detect orphans in Content DB:
- Run following script in power shell
- Script runs at Farm level, enumerates thru each web app and each site collection in each web app
- Script is Read-Only (just detects orphans – if any)
- More Info on stsadm -o databaserepair command http://technet.microsoft.com/en-us/library/cc263282(v=office.12).aspx
- The reason I am enumerating stsadm.exe as an object within PowerShell is because there is no equivalent PowerShell cmdlet for stsadm -o databaserepair in SP2010. More Info: http://technet.microsoft.com/en-us/library/ff621084.aspx
SCRIPT
----------------------------------------------------------------------------------------------------------------------------------
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
----------------------------------------------------------------------------------------------------------------------------------
- To delete orphan objects from a particular site use following script
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{Add-PSSnapin Microsoft.SharePoint.Powershell}
set-location "C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN"
stsadm.exe -o databaserepair -url -databasename >> C:\SPSiteOrphansDelete.txt
Note
- You can get the Content DB of a particular site collection using below script
$site=Get-SPSite
write-host $site.ContentDatabase.Name