Created
March 25, 2013 13:51
-
-
Save nlarkin/5237244 to your computer and use it in GitHub Desktop.
Powershell Script to force a undocheckout of a specified document using the bypasslocks method.
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
cls | |
$error.Clear() | |
################################################################################################## | |
# Load SharePoint Snapin | |
################################################################################################## | |
$snap = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'} | |
if ($snap -eq $null) { | |
Write-Host "Loading Powershell Snapin..." -ForegroundColor Yellow | |
Add-PSSnapin Microsoft.SharePoint.Powershell | |
} | |
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null | |
$checkout = { | |
param( [Microsoft.SharePoint.SPListItem]$a ) | |
$a.File.UndoCheckOut() | |
$a.File.Update() | |
$a.SystemUpdate($true) | |
} | |
function UnlockFile($item) | |
{ | |
if ($item.File.CheckOutStatus -ne "None" ) | |
{ | |
[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::bypasslocks($item, $checkout) | |
} | |
} | |
$url = "http://sharepointsite.com/site" | |
$fileurl = "http://sharepointsite.com/site/Documents/FullDocURL.pdf" | |
$web = Get-SPWeb $url | |
$item = $web.GetListItem($fileurl) | |
UnlockFile $item | |
$web.Dispose() |
Thanks a lot.. I was stuck with this for 2days and finally this code helped 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
When I try to use the script, I get below error,
Exception calling "BypassLocks" with "2" argument(s): "Attempted to perform an unauthorized operation."
On Line:
[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::bypasslocks($item, $checkout)
Even though executing the script as administrator, I have Site Collection Administrator rights on the site. I am still getting this error.
Can you help me.