The script below helps you find the orphaned items from SharePoint content databases
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{Add-PSSnapin Microsoft.SharePoint.Powershell}
$CntDBs = Get-SPContentDatabase
ForEach ($CntDB in $CntDBs)
{
Write-Host "Detecting Orphans for " $CntDB.Name $CntDB.Repair($false)
}
The above script will only list down the Orphaned items. You can also repair these by changing
$CntDB.Repair($false) to $CntDB.Repair($true)
However before doing any such repair, you should be taking a back up of your DB.
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{Add-PSSnapin Microsoft.SharePoint.Powershell}
$CntDBs = Get-SPContentDatabase
ForEach ($CntDB in $CntDBs)
{
Write-Host "Detecting Orphans for " $CntDB.Name $CntDB.Repair($false)
}
The above script will only list down the Orphaned items. You can also repair these by changing
$CntDB.Repair($false) to $CntDB.Repair($true)
However before doing any such repair, you should be taking a back up of your DB.
Many many thanks for this script.
ReplyDeleteItems includes only site collections and sub sites within the content DBs?
Great Post!
ReplyDeleteThanks a lot for sharing!
I found this blog to be very useful!!
PowerShell training in Bangalore