Last active
September 7, 2020 15:20
-
-
Save tiagoduarte/526771ade957995de382fe18f7e85c65 to your computer and use it in GitHub Desktop.
Release SharePoint file lock using PowerShell
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
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