Get All Checked Out Items From A Site Collection Using PowerShell In SharePoint 2013

This article will help developers to get the checked out items in a site collection to ease out the migration journey

At some point, your architect/manager/customer may ask you to perform a SharePoint Migration from one version to another version. At that time, you'll be asked to analyze a lot of factors, like total data to be migrated, workflows, solution files etc. Along with that, one of the most important things is files uploaded in the document library.

SharePoint

Let’s say, for example, you use the Metalogix Context Matrix tool. In that, the checked out files in document library won't be migrated. To identify the files which are checked out in the entire site collection is a very tedious task manually. The below piece of PowerShell code makes life easier by getting the checked out files in the site collection in one shot. Here is the PowerShell code which will get the document library items from the site collection which are checked out. 

  1. #Add the PowerShell SnapIn Add - PSSnapin microsoft.sharepoint.powershell  
  2. # Enter the Site Collection URL $spWeb = Get - SPWeb "http://insiscvmsrv70:8888/sites/KM/"  
  3. #Function to get the CheckedOut items in document library  
  4.   
  5. function GetCheckedItems($spWeb) {  
  6.     Write - Host "Scanning Site: $($spWeb.Url)"  
  7.     foreach($list in ($spWeb.Lists | ? {  
  8.         $_ - is[Microsoft.SharePoint.SPDocumentLibrary]  
  9.     })) {  
  10.         Write - Host "Scanning List: $($list.RootFolder.ServerRelativeUrl)"  
  11.         foreach($item in $list.CheckedOutFiles) {  
  12.             if (!$item.Url.EndsWith(".aspx")) {  
  13.                 continue  
  14.             }  
  15.             $writeTable = @ {  
  16.                 "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");  
  17.                 "Checked Out By" = $item.CheckedOutBy;  
  18.                 "Author" = $item.File.CheckedOutByUser.Name;  
  19.                 "Checked Out Since" = $item.CheckedOutDate.ToString();  
  20.                 "File Size (KB)" = $item.File.Length / 1000;  
  21.                 "Email" = $item.File.CheckedOutByUser.Email;  
  22.             }  
  23.             New - Object PSObject - Property $writeTable  
  24.         }  
  25.         foreach($item in $list.Items) {  
  26.             if ($item.File.CheckOutStatus - ne "None") {  
  27.                 if (($list.CheckedOutFiles | where {  
  28.                         $_.ListItemId - eq $item.ID  
  29.                     }) - ne $null) {  
  30.                     continue  
  31.                 }  
  32.                 $writeTable = @ {  
  33.                     "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");  
  34.                     "Checked Out By" = $item.File.CheckedOutByUser.LoginName;  
  35.                     "Author" = $item.File.CheckedOutByUser.Name;  
  36.                     "Checked Out Since" = $item.File.CheckedOutDate.ToString();  
  37.                     "File Size (KB)" = $item.File.Length / 1000;  
  38.                     "Email" = $item.File.CheckedOutByUser.Email;  
  39.                 }  
  40.                 New - Object PSObject - Property $writeTable  
  41.             }  
  42.         }  
  43.     }  
  44.     foreach($subWeb in $spWeb.Webs) {  
  45.         GetCheckedItems($subWeb)  
  46.     }  
  47.     $spWeb.Dispose()  
  48. }  
  49. GetCheckedItems($spWeb) | Out - GridView  
  50. # As an alternate option you can export the data to a textfile as well.Uncomment below code to do that  
  51. # GetCheckedItems($spWeb) | Out - File c: \CheckedOutItemsInSiteCollection.txt - width 300  

Once you run the PowerShell script using PowerShell ISE, you get the below output.

Output

 

Hope it helps fellow developers.