Thursday, September 26, 2013

Checking in all files in a document library which is checked out to someone using PowerShell

Background and Problem
Recently we had to check in a large number of files in that were checked out to me due to another process that we had run. SharePoint does provide a simple way to do this for many files, but since we also had to run this over several document libraries.

The Solution

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
 
function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)
}
 
#Change these variables to your site URL and list name
$siteColletion = Get-SPSite("http://example.org/");

$folder = $siteColletion.RootWeb.Folders["Documents"];

$collFiles = $folder.Files;

for ($intIndex=0; $intIndex -ne $folder.Count; $intIndex++)
{
    if ($folder[$intIndex].CheckedOutBy.LoginName -eq "domain\ortegroadmin")
    {
        $folder[$intIndex].CheckIn("");
    }
}
#Dispose of the site object
$siteColletion.Dispose()

No comments:

Post a Comment