1

there is a file I want to delete but it is locked. I see with powershell that the lock type is Shared.

>$item = $web.GetListItem('pathtomyfile')
>$item.file.locktype
>Shared

Can I change or remove the locktype with Powershell?

1

Following is the powershell script for removing/releasing lock from any document from SharePoint

$web = Get-SPWeb http://intranet.contoso.com 
$list = $web.Lists["DocLib"] 
$item = $list.GetItemById(2) 
$file = $item.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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.