Monday 18 November 2013

Orphans Object Clean Up in SharePoint

Orphaned Objects are items that do not have any parent or child relationship and remain in the content database uncleaned. When  you perform the Test-SPContentDatabase to validate a content database you might receive errors which provides information about orphans in the content database

These orphaned objects need to be removed on the below situations:
1. Before applying service packs or cumulative updates to the SharePoint servers
2. Before performing a migration from a older version of SharePoint to a newer version.
3. Before reapplying templates or performing any updates to the database.(certain powershell commands would not work when running update scripts on the database.  ex. Applying modification to a Custom Master Page that is already deployed to the sites). The execution of powershell scripts will fail when iterating the tables for fetching or applying update to the data in SharePoint content databases


There are 2 types of Orphan Objects
1. Config Orphans (Orphan Site exist in Configuration Database but does not have any child item in Content Database). Central Admin ->View All Site Collections shows the site info, but the actual site cannot be accessed via browser. 
2. Content Orphans (Orphans include Lists without Parent sites, Documents with no parent document library, Web Parts that does not have an assembly, Web Pages with no Parent Site E.t.c..). Site Collections that are available in content database but not in config db (Will not show in Central Admin -> View All Site Collections page)
  


A.    Config Orphan Object Removal:
Cleaning the config orphan is the easiest one.
Simply detach the content database that has the orphan site from your farm and attach it back. This will refresh and remove the stale entries.

B.     Content Orphan Object Removal
There are 2 ways to remove content orphans from the content database
1. Use SharePoint Health Analyzer
2. Use STSADM or PowerShell Commands

1.      SharePoint Health Analyzer 
(Note : Not recommended in a Production farm as it sometimes might cause SQL Blocking if there are very large content databases)
Go to Central Admin - > Monitoring > Health Analyzer Section > Review Problems and Solutions > Content Database Contain Orphaned Items - Click on the Ribbon Command "Repair Automatically".

2.      Using STSADM Commands

I have provided two scripts to first log the orphans in text file.(STSADM Method)
When you execute the first script, this will list out the orphaned objects in text file
The second one will delete the orphans.
This method will delete only when you have orphan sites in one content database.

Modify the site collection name and database name related to the STSADM command line. 


To Check Orphans (Store the below content in a .Bat file)

echo on
rem ***  set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection -databasename Content10_ContentDB  >> %LogFile%

Echo "************** E N D*********" >> %LogFile%
pause

PowerShell Command to check orphans:

$contentdb = Get-SPContentDatabase | Where-Object {$_.Name –match "Content_Contentdb"}
test-spcontentdatabase $contentdb -showrowcounts | Format-Table -Wrap | Out-File -FilePath c:\testcontent.txt

To Delete Orphans(Store the below content in a .Bat file):

echo on
rem ***  set local environment variables
setlocal
set LogFile="D:\LogOrphans.txt"
c:
cd "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN" >> %LogFile%
Echo "List Orphans ...." >> %LogFile%
stsadm.exe -o databaserepair -url https://contoso.com/sites/sitecollection -databasename Content10_ContentDB -deletecorruption  >> %LogFile%

Echo "************** E N D*********" >> %LogFile%
pause


The Ouput in log File below:
"List Orphans ...." 
<OrphanedObjects Count="43">
<Orphan Type="SPWeb" Name="Contoso Sub Site0" Id="{B779C412-8AE4-4D3B-877C-BFB41F94E735}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site1" Id="{46F35180-7758-4ED5-8C51-3E7E3D1D5441}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site10" Id="{252EAB85-7535-4141-8BFB-2982BCACE095}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site11 (en)" Id="{9F5B2BCA-2B4E-4E01-B3C4-401A9C078C25}" Deleted="Yes" />
  <Orphan Type="SPWeb" Name="Contoso Sub Site12 (fr)" Id="{5E9342E3-2BF1-4692-ACB8-A900307992F2}" Deleted="Yes" />
<Orphan Type="SPList" Id="{1F90BF81-1965-460E-8F46-85655BEFB306}" SiteId="{5E9342E3-2BF1-4692-ACB8-A900307992F2}" />

</OrphanedObjects>
"************** E N D*********" 
Note:
In some scenarios certain orphan object might not get removed, but still show that it is removed and will remain in the database. 
To validate this, run the below command to list the objects in the content database and cross verify with the log files

stsadm -o enumallwebs -databasename Content10_ContentDB 

Output of the above Stsadm command

<Sites Count="2">
  <Site Id="9F5B2BCA-2B4E-4E01-B3C4-401A9C078C25" OwnerLogin="Domain\username" InSiteMap="False">
    <Webs Count="1">
      <Web Id="064d8e7b-b349-4693-bd67-dcefed3bf466" Url="/sites/contososubsite11" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
    </Webs>
  </Site>
  <Site Id="f440114b8-79d9-32f6-87bf-4geddf2ad9b6" OwnerLogin="Domain\username" InSiteMap="True" HostHeader="www.contoso.com">
    <Webs Count="1">
      <Web Id="12348e7b-c456-4693-bd67-efdegd3bf466" Url="/" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
    </Webs>
  </Site>
</Sites>

If the property InSiteMap=False then the site collection is an orphan.

Final Validation:
If you still have the orphaned objects listed, then try the below options and then validate again with the log file
1. Disconnect the database and reconnect the database so that the references will be removed.
2. Try removing the corrupted list or item using the sharepoint designer tool.
3. Try deleting the site using below Stsadm commands
stsadm -o deletesite -force -url http://contoso.com/sites/contososubsite11 -databaseserver ds -databasename contentdb1
(or)
stsadm -o deletesite -force -siteid e2a114b8-80c9-41f6-87bf-3feddf2ad9b6 -databaseserver ds -databasename contentdb1

4.  Try running the below Powershell commands
(Get-SPContentDatabase <DB Name>).Repair($true)
Ex:

(Get-SPContentDatabase Collab_ContentDB).Repair($true)



35 comments:

  1. This blog is so nice to me. I will keep on coming here again and again. Visit my link as well..
    delete cheaterland.com complaint 

    ReplyDelete
  2. I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
    python training in tambaram
    python training in chennai
    python training in annanagar
    python training in chennai

    ReplyDelete
  3. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.

    Best RPA Training in Chennai
    Digital Marketing Training in Chennai
    Matlab Training in Chennai
    Best AWS Course Training in Chennai

    ReplyDelete

  4. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!!
    www.excelr.com/digital-marketing-training
    digital marketing course

    ReplyDelete
  5. I always enjoyed by reading your blogs. The information which your blog consist outstanding I couldn't found it anywhere else. Please keep posting the blogs. Even I had started writing blogs since I am a fresher I have no much idea about it. u can suggest me any good blogger who can help .

    Thanks and Regards,
    Digital Marketing Course

    ReplyDelete
  6. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    Aws training chennai | AWS course in chennai
    Rpa training in chennai | RPA training course chennai

    ReplyDelete
  7. very nice blog keep on doing...

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery

    ReplyDelete
  8. My spouse and I love your blog and find almost all of your post’s to be just what I’m looking for. Can you offer guest writers to write content for you? I wouldn’t mind producing a post or elaborating on some the subjects you write concerning here. Again, awesome weblog!
    AWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

    ReplyDelete
  9. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

    DevOps Training in Chennai

    DevOps Course in Chennai

    ReplyDelete
  10. Worth reading! Our experts also have given detailed inputs about these trainings & courses! Presenting here for your reference. Do checkout Data Science Training in Chennai & enjoy learning more about it.

    ReplyDelete
  11. Information was good,i like your post.Looking forward for more on this topic.
    Sharepoint Admin training in bangalore

    ReplyDelete
  12. If AWS is a job that you're dreaming of, then we, Infycle are with you to make your dream into reality. Infycle Technologies offers the best AWS Course Chennai, with various levels of highly demanded software courses such as Oracle, Java, Python, Hadoop, Big Data, etc., in 100% hands-on practical training with specialized tutors in the field. Along with that, the pre-interviews will be given for the candidates, so that, they can face the interviews with complete knowledge. To know more, dial 7502633633 for more.Best AWS Training in Chennai

    ReplyDelete
  13. Brilliant post! We are connecting to this extraordinary post on our site. Keep up the extraordinary composition. best interiors

    ReplyDelete
  14. We are added much functionality in this Remove object from photo and Remove BG from photo app like remover, clone stamp, background eraser, quick remover, transparent background and cloth remover.

    ReplyDelete
  15. Existing without the answers to the difficulties you’ve sorted out
    through this guide is a critical case, as well as the kind which could
    have badly affected my entire career if I had not discovered your
    website.
    mysql dba training in chennai
    unix course in chennai
    top software training institute in Chennai

    ReplyDelete
  16. Nice blog thank you .For your Sharing It's a pleasure to read your post.It's full of information I'm looking for and I'd like to express that "The content of your post is awesome"

    Dotnet Training in Chennai
    Core java Training in Chennai
    Web design Training in Chennai

    ReplyDelete
  17. 1xbet korean Sports Betting - Bet with 1xbet Limited
    1xbet korean Sports Betting. Bet with 1xbet Limited. Get up to 1xbet 1xbet deposit.

    ReplyDelete
  18. Eimple Labs born to prepare an industry ready workforce. As a product based company Eimple Labs ensures to inculcate the end to end live product development and management skills. We work in a university-industry partnership and implement a holistic knowledge-imparting model to prepare students for new-collar jobs in emerging industries.

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. This comment has been removed by the author.

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete