top of page

How to remove from a hold using PowerShell and programmatically in SharePoint 2010

In this article we will be seeing how to remove from a hold in SharePoint 2010 using PowerShell and C#.

Refer http://www.c-sharpcorner.com/UploadFile/anavijai/5103/ to create a hold and add or remove the hold to the item through UI.

In this article

  • Remove from a hold using c#

  • Remove from a hold using PowerShell

Remove from a hold using c#

  • Open Visual Studio 2010.

  • Create a new console application.

  • Add the following references.

        1) Microsoft.Office.Policy.dill         2) Microsoft.SharePoint.dill

  • Add the following namespaces.

        1) using Microsoft.Sharepont;         2) using Microsoft.Office.RecordsManagement.Holds;

  • Replace the code with the following.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.Office.RecordsManagement.Holds; namespace Holds { class Program

{ static void Main(string[] args) { using (SPSite site = new SPSite("http://serverName:1111/")) { using (SPWeb web = site.RootWeb)

{ //Removes the specified item from the specified hold SPList list = web.Lists["Shared Documents"]; SPListItem item = list.Items[0]; SPList listHolds = web.Lists["Holds"]; SPListItem itemHold = listHolds.Items[1]; Hold.RemoveHold(item, itemHold, "Hold removed"); 

//Removes the specified items from the specified hold.

SPListItemCollection items = list.Items; Hold.RemoveHold(items, itemHold, "Hold Removed from all the items");  } } } } }


Removes the specified item from the specified hold:









Removes the specified items from the specified hold:










Remove from a hold using PowerShell

Removes the specified item from the specified hold:

$siteURL="http://serverName:1111/" $site=Get-SPSite $siteURL $web=$site.RootWeb $list = $web.Lists["Shared Documents"]; $item = $list.Items[0]; $listHOlds = $web.Lists["Holds"] $itemHold=$listHOlds.Items[0]; [Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($item,$itemHold,"Hold removed") $web.Dispose() $site.Dispose()

Removes the specified item from the specified hold:

$siteURL="http://serverName:1111/" $site=Get-SPSite $siteURL $web=$site.RootWeb $list = $web.Lists["Shared Documents"]; $items = $list.Items; $listHOlds = $web.Lists["Holds"] $itemHold=$listHOlds.Items[0]; [Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($items,$itemHold,"Hold removed from all the items") $web.Dispose() $site.Dispose()

0 comments
bottom of page