Skip to content

Instantly share code, notes, and snippets.

@tiagoduarte
Last active September 7, 2020 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoduarte/526771ade957995de382fe18f7e85c65 to your computer and use it in GitHub Desktop.
Save tiagoduarte/526771ade957995de382fe18f7e85c65 to your computer and use it in GitHub Desktop.
Release SharePoint file lock using PowerShell
param(
$webUrl = "http://demosite",
$listTitle = "testlib",
$itemID = 183
)
clear-host
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listTitle]
$item = $list.GetItemById($itemID)
$file = $item.File
$lockType = $file.LockType
if($lockType -ne "None")
{
$userID = $file.LockedByUser.ID
$user = $web.AllUsers.GetByID($userID)
$lockID = $file.LockId
write-host "file locked"
write-host "user id $userID"
write-host "lock type $lockType"
$file.ReleaseLock($lockID)
write-host "file unlocked!"
}
else
{
write-host "file not locked"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment