Showing posts with label Orphan. Show all posts
Showing posts with label Orphan. Show all posts

Find Orphaned SharePoint Items using PowerShell script

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.