To get the orphan objects on the specific content database please execute the below commands:
- $CDB = Get-SPContentDatabase -identity "GUID of the content database"
- $CDB.Repair($false) # $false to return the orphan objects
In order to clean the orphan objects, execute the below command:
To get the GUID of specific content database attached to a web application, execute below commands:
- $dbs = get-spwebapplication "Webapplication URL"
- $dbs.ContentDatabases
Now you will get list of content databases attached to the web application and its details. Grab the content database ID from here and use it in your command.