Release Locked (checked out) Document in SharePoint


As a feature in SharePoint, you can check out any document item.

Sometime, the user who check out the document library is not available and the admin need to release (undo check-out) the document library.

We can use the following power shell script (Change the bold values)

$WebSiteURL="http://sps-dev/"
$DocLibName="DocLib"
$ItemID=5

$web=Get-SPWeb $WebSiteURL
$item=$web.Lists[$DocLibName].GetItemById($ItemID)
$userId=$item.file.LockedByUser.ID
$user = $web.AllUsers.GetByID($userId)

$impSite= New-Object Microsoft.SharePoint.SPSite($web.Url, $user.UserToken)
$impWeb = $impSite.OpenWeb()
$impList=$impWeb.Lists["Appraisal"]
$impitem=$impList.GetItemById($item.ID)
$impitem.file.ReleaseLock($impitem.File.LockId)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s