top of page

Get the list of holds for the specified item using Powershell and programmatically in SharePoint


In this article we will be seeing how to get the list of holds for the specified list item using powershell and programmatically in SharePoint 2010.

For Holds and Hold Reports in SharePoint 2010 http://www.c-sharpcorner.com/UploadFile/anavijai/5103/  (Copy the hyperlink).

I have created two hold items "HR" and "Finance" in the Holds list


Which is available in Site Actions => Site Settings => Hold and eDiscovery => Holds.






In the Shared documents I have an item "New" for which both "HR" and "Finance" holds are added.


Programmatically get the list of holds for the item "New":

1. Open Visual Studio 2010.

2. Create a new console application.

3. Add the following references.

a. Microssoft.Office.Policy.dll

b. Microsoft.SharePoint.dll

4. Add the following namespaces.

a. using Microsoft.SharePoint;

b. using Microsoft.Office.RecordsManagement.Holds;

5. Replace the code with the following.

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Microsoft.SharePoint;

  6. using System.Xml;

  7. using Microsoft.SharePoint.Administration;

  8. using Microsoft.Office.RecordsManagement.Holds;

  9. namespace GetHolds

  10. {

  11. class Program   

  12. {

  13. static void Main(string[] args)       

  14. {

  15. using (SPSite site = new SPSite("http://servername:22222/sites/Test/"))           

  16. {

  17. using (SPWeb web = site.RootWeb)               

  18. {

  19. SPList list = web.Lists["Shared Documents"];

  20. foreach (SPListItem item in list.Items)                   

  21. {

  22. if (item.DisplayName.ToString() == "New")                       

  23. {

  24. List<SPListItem> holds = Hold.GetHolds(item);

  25. foreach (SPListItem holdItem in holds)                           

  26. {

  27. Console.WriteLine(holdItem.Title);                           

  28. }                       

  29. }                   

  30. }                 

  31. Console.ReadLine();               

  32. }                           

  33. }                  

  34. }   

  35. }

  36. }

  • Build the solution.

  • Hit F5.


Output:





Gets the list of holds for the item "New" using powershell:

1. Go to Start => All Programs => Microsoft SharePoint 2010 Products => SharePoint 2010 Management Shell.

2. Run as an administrator.

3. Run the following script.

  1. $site = get-SPSite("http://serverName:22222/sites/Test/")

  2. $web = $site.RootWeb

  3. $list = $web.Lists["Shared Documents"]foreach ($item in $list.Items)

  4. {

  5. if ($item.DisplayName.ToString() -eq "New")

  6. {

  7. $holds = [Microsoft.Office.RecordsManagement.Holds.Hold]::GetHolds($item)

  8. foreach ($holdItem in $holds)

  9. {

  10. write-host -f green $holdItem.Title

  11. }

  12. }

  13. }

0 comments
bottom of page