Home > PowerShell, SharePoint Administration > Getting a List of All Checked-Out Files with No Checked-In Versions in SharePoint 2007 Using PowerShell

Getting a List of All Checked-Out Files with No Checked-In Versions in SharePoint 2007 Using PowerShell

I needed to generate a list of all documents that were checked out but never had a checked-in version.  I needed to do this for a few Site Collections in my MOSS 2007 Farm.  Thanks to Gary LePointe he has already done the hard work for us. http://blog.falchionconsulting.com/index.php/2011/06/getting-and-taking-ownership-of-checked-out-files-using-windows-powershell/#comment-52052

I basically just took his script which works great in SP2010 and modified it a little to work with MOSS 2007

Please see script below.

**UPDATE** — The 1st Script below only returns documents that are checked out, not documents that are checked out with no checked in version.

**See script 2–the one below this one to get a report of all checked out documents with no checked in version**

—————————Get All Checked Out Documents———————————————————————————————————-

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

$siteURL=”http://portal/site”
$site=New-Object Microsoft.SharePoint.SPSite($siteURL)

function Get-CheckedOutFiles()
{
    foreach ($web in $site.AllWebs)
    {
        Write-Host “Processing Web: $($web.Url)…”
        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}))
        {
            Write-Host “`tProcessing List: $($list.RootFolder.ServerRelativeUrl)…”
            foreach ($item in $list.CheckedOutFiles)
            {
                if (!$item.Url.EndsWith(“.aspx”)) { continue }
                $hash = @{
                        “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
                        “CheckedOutBy”=$item.CheckedOutBy;
                        “CheckedOutByEmail”=$item.CheckedOutByEmail
                    }
                    New-Object PSObject -Property $hash
            }
            foreach ($item in $list.Items)
            {
                if ($item.File.CheckOutStatus -ne “None”)
                {
                    if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) { continue }
                    $hash = @{
                            “URL”=$web.Site.MakeFullUrl(“$($web.ServerRelativeUrl.TrimEnd(‘/’))/$($item.Url)”);
                            “CheckedOutBy”=$item.File.CheckedOutBy;
                            “CheckedOutByEmail”=$item.File.CheckedOutBy.Email
                        }
                        New-Object PSObject -Property $hash
                }
            }
        }
    $web.Dispose()
    }
}

Get-CheckedOutFiles | Out-GridView

—————————————————————————————————————————————————–

———————–Get All Checked Out Documents with no Checked In Version—————————————

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

function CheckedOutItems()
{
    $url=Read-Host “Please Enter In Site Url”
    “SiteURL ‘t” + “FileName ‘t” + “CheckedOutTo ‘t” + “ModifiedDate ‘t” + “Version” >> c:\temp\checkedoutfiles.csv
    $site = New-Object Microsoft.SharePoint.SPSite($url)
    $webs = $site.AllWebs
    
    foreach($web in $webs)
    {
        $listCollections=$web.Lists
        foreach($list in $listCollections)
        {
            if($list.BaseType.ToString() -eq “DocumentLibrary”)
            {
                $dList=[Microsoft.SharePoint.SPDocumentLibrary]$list
                $items = $dList.Items
                $files = $dList.CheckedOutFiles
                foreach($file in $files
                {
                    $wuse=$file.DirName.Substring($web.ServerRelativeUrl.Length)
                    $web.Url + “‘t” + $wuse + “‘/” + $file.LeafName + “‘t” + $file.CheckedOutBy.Name + “‘t” + $file.TimeLastModified.ToString() + “‘t” + “No Checked In Version” >> c:\temp\checkedoutfiles.csv
                }
            }
        }
    $web.Dispose()
    }
$site.Dispose()
}

CheckedOutItems

———————————————————————————————————————————————————————————-

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: