Saturday, August 29, 2015

PowerShell to unlock the files which are locked from SharePoint

 

 

$web = Get-SPWeb http://<site>/Ringo

$list = $web.Lists["Shared Documents"]

$item = $list.GetItemById(171)

$file = $item.File

$file

$userId = $file.LockedByUser.ID

$user = $web.AllUsers.GetByID($userId)

$impSite= New-Object Microsoft.SharePoint.SPSite($web.Url, $user.UserToken);

$impWeb = $impSite.OpenWeb();

$impList = $impWeb.Lists[$list.Title]

$impItem = $impList.GetItemById($item.ID)

$impFile = $impItem.File

$impFile.ReleaseLock($impFile.LockId)

 

No comments:

Post a Comment