Skip to content

Instantly share code, notes, and snippets.

@devendrasv
Last active December 24, 2015 23:18
Show Gist options
  • Save devendrasv/6878649 to your computer and use it in GitHub Desktop.
Save devendrasv/6878649 to your computer and use it in GitHub Desktop.
Get all checkedout items in a site collection
#function to get checked-out files
function CheckedOutItems()
{
write-host "Please enter the site url"
#Reading the site collection URL
$url = read-host
#Writing the header text to a file
write ("SiteURL`t" + "FileName`t" + "CheckedOutTo`t" + "ModifiedDate`t"+"Version")
$site = New-Object Microsoft.SharePoint.SPSite($url)
#Getting all sub sites in a site collection
$webs = $site.AllWebs
foreach($web in $webs)
{
#Getting all lists in the sub site
$listCollections = $web.Lists
foreach($list in $listCollections)
{
#Checing whether the list is of type document library
if ($list.BaseType.ToString() -eq "DocumentLibrary")
{
$dList = [Microsoft.Sharepoint.SPDocumentLibrary]$list
$items = $dList.Items
#Out of alll files getting only checked-out files
$files = $dList.CheckedOutFiles
foreach($file in $files)
{
$wuse = $file.DirName.Substring($web.ServerRelativeUrl.Length)
Write ($web.Url+ "`t" + $wuse+"`/" + $file.LeafName + "`t" + $file.CheckedOutBy.Name + "`t" + $file.TimeLastModified.ToString()+"`t" + "No Checked In Version" )
}
foreach($item in $items)
{
if ($item["Checked Out To"] -ne $null)
{
$splitStrings = $item["Checked Out To"].ToString().Split('#')
Write ($web.Url+ "`t" + $item.Url + "`t" + $splitStrings[1].ToString() + "`t" + $item["Modified"].ToString() +"`t" + $item["Version"].ToString())
}
}
}
}
$web.Dispose()
}
$site.Dispose()
}
CheckedOutItems >> E:\checkedout.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment