-
-
Save MudassarAli/a2dcde17357785c2d1234d9d6e298e3f 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment