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. function GetCheckedItems($spWeb) {
  5. Write - Host "Scanning Site: $($spWeb.Url)"
  6. foreach($list in ($spWeb.Lists | ? {
  7. $_ - is[Microsoft.SharePoint.SPDocumentLibrary]
  8. })) {
  9. Write - Host "Scanning List: $($list.RootFolder.ServerRelativeUrl)"
  10. foreach($item in $list.CheckedOutFiles) {
  11. if (!$item.Url.EndsWith(".aspx")) {
  12. continue
  13. }
  14. $writeTable = @ {
  15. "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
  16. "Checked Out By" = $item.CheckedOutBy;
  17. "Author" = $item.File.CheckedOutByUser.Name;
  18. "Checked Out Since" = $item.CheckedOutDate.ToString();
  19. "File Size (KB)" = $item.File.Length / 1000;
  20. "Email" = $item.File.CheckedOutByUser.Email;
  21. }
  22. New - Object PSObject - Property $writeTable
  23. }
  24. foreach($item in $list.Items) {
  25. if ($item.File.CheckOutStatus - ne "None") {
  26. if (($list.CheckedOutFiles | where {
  27. $_.ListItemId - eq $item.ID
  28. }) - ne $null) {
  29. continue
  30. }
  31. $writeTable = @ {
  32. "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
  33. "Checked Out By" = $item.File.CheckedOutByUser.LoginName;
  34. "Author" = $item.File.CheckedOutByUser.Name;
  35. "Checked Out Since" = $item.File.CheckedOutDate.ToString();
  36. "File Size (KB)" = $item.File.Length / 1000;
  37. "Email" = $item.File.CheckedOutByUser.Email;
  38. }
  39. New - Object PSObject - Property $writeTable
  40. }
  41. }
  42. }
  43. foreach($subWeb in $spWeb.Webs) {
  44. GetCheckedItems($subWeb)
  45. }
  46. $spWeb.Dispose()
  47. }
  48. GetCheckedItems($spWeb) | Out - GridView
  49. # As an alternate option you can export the data to a textfile as well.Uncomment below code to do that
  50. # 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.