Checking in Documents through Powershell


Niklas Goude
-Expert in Residence

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

Twitter This Tip! ReTweet this Tip!


Posted Aug 18 2010, 08:00 AM by sos

Comments

Twitter Trackbacks for Checking in Documents through Powershell - SharePoint Tips - Secrets of SharePoint [secretsofsharepoint.com] on Topsy.com wrote Twitter Trackbacks for Checking in Documents through Powershell - SharePoint Tips - Secrets of SharePoint [secretsofsharepoint.com] on Topsy.com
on 08-18-2010 11:21 AM

Pingback from  Twitter Trackbacks for                 Checking in Documents through Powershell - SharePoint Tips - Secrets of SharePoint         [secretsofsharepoint.com]        on Topsy.com

Idera SharePoint Reviews SMBology, Inc. Rackspace Hosting Sponsored by Idera and SharePoint Reviews and SMBology and EPCGroup.net
Copyright 2011 SecretsOfSharePoint.com. All rights reserved.