Created
February 9, 2018 09:08
-
-
Save fabianneve/35f162919a7084af85a89870238d3741 to your computer and use it in GitHub Desktop.
Clear short term file lock of a file in a SharePoint 2013+ document library when the file is still open by the user. Replace url, list (List Title) and item ID.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$web = get-spweb "https://domain/sitecollection/site" | |
$list = $web.Lists["Documents"] | |
$item = $list.Items.GetItemById(123) | |
$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[$list.Title]; | |
$impItem = $impList.GetItemById($item.ID); | |
$impItem.File.ReleaseLock($impItem.File.LockId) | |
$impWeb.Dispose() | |
$impSite.Dispose() | |
$web.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment