Have you ever wanted to modify a document that someone forgot to check in? Or maybe a user forgot to check in his documents before going on a 2 year vacation. Using Windows PowerShell, you can check for documents that are checked out and perform an action if a document is checked out. In this example we’ll simply check in the document but it’s possible to send a mail to the user instead and ask him/her to check in the document.
function CheckInDocument([string]$url) {
$spWeb = Get-SPWeb $url
$getFolder = $spWeb.GetFolder("Shared Documents")
$getFolder.Files | Where { $_.CheckOutStatus -ne "None" } | ForEach {
Write-Host "$($_.Name) is Checked out To: $($_.CheckedOutBy)"
$_.CheckIn("Checked In By Administrator")
Write-Host "$($_.Name) Checked In" -ForeGroundColor Green
}
$spWeb.Dispose()
}
Here’s an example on running the function:
CheckInDocument http://SP
ReTweet this Tip!
Posted
Aug 18 2010, 08:00 AM
by
sos