Objective

This purpose of this document is to mention the steps to get a list of all the checked out files in a web application. The reusable script for this job is also attached with this document. This script offers,

Business Case

S. No.Business Case
1Before we go ahead and start doing migration we need to extract many report and insights about the current SharePoint environment. One of those need is to get a list of checked out files in your SharePoint. This script will allow administrator to do this job easily.

Targeted Audience

Offerings

Technical Details

Below are the technical details for this PowerShell script,

  1. Execution

    Prerequisite:

    Login to SharePoint Server as Farm Administrator and copy the required files as per your requirement.

    Run:

    • Run the PowerShell Script as “Run as Administrator“.
    • Browse the folder path where you have kept this PowerShell script file and execute a command.

      command

PowerShell Script

  1. ##########################################################################################################################
  2. ######## V 1.0
  3. ######## PowerShell Script to get a list of checked out files in your SharePoint Environment
  4. ################################################################################################################################
  5. #check to see if the PowerShell Snapin is added
  6. if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
  7. Add-PSSnapin Microsoft.SharePoint.PowerShell;
  8. }
  9. ## SharePoint DLL
  10. [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  11. $global:currentPhysicalPath = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
  12. Function Get-SPWebApplication()
  13. {
  14. Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
  15. return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
  16. }
  17. Function global:Get-SPSite()
  18. {
  19. Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )
  20. if($SiteCollURL -ne '')
  21. {
  22. return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
  23. }
  24. }
  25. Function global:Get-SPWeb()
  26. {
  27. Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
  28. $site = Get-SPSite($SiteURL)
  29. if($site -ne $null)
  30. {
  31. $web=$site.OpenWeb();
  32. }
  33. return $web
  34. }
  35. #EndRegion
  36. Function GetCheckedOutFiles([string]$WebAppURL)
  37. {
  38. try
  39. {
  40. $results = @()
  41. #Get the Web Application
  42. $WebApp=Get-SPWebApplication($WebAppURL)
  43. #Arry to Skip System Lists and Libraries
  44. $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates",
  45. "List Template Gallery", "Theme Gallery", "Reporting Templates", "Solution Gallery",
  46. "Style Library", "Web Part Gallery","Site Assets", "wfpub","Site Pages")
  47. #Loop through each site collection
  48. foreach($Site in $WebApp.Sites)
  49. {
  50. #Loop through each site in the site collection
  51. foreach($Web in $Site.AllWebs)
  52. {
  53. #Loop through each document library
  54. foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
  55. {
  56. #Get only Document Libraries & Exclude Hidden System libraries
  57. if (($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
  58. {
  59. #Loop through eadh Item
  60. foreach ($ListItem in $List.Items)
  61. {
  62. if( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
  63. {
  64. $sitecollectionUrl = "<SiteCollection relativeURL=" + $Site.RootWeb.ServerRelativeURL + "></SiteCollection>"
  65. #Create an object to hold storage data
  66. $resultsData = New-Object PSObject
  67. $resultsData | Add-Member -type NoteProperty -name "SiteCollection Title" -value $Site.RootWeb.Title -Force
  68. $resultsData | Add-Member -type NoteProperty -name "SiteCollection URL" -value $sitecollectionUrl -Force
  69. $resultsData | Add-Member -type NoteProperty -name "Web Title" -value $Web.Title -Force
  70. $resultsData | Add-Member -type NoteProperty -name "Web URL" -value $Web.url -Force
  71. $resultsData | Add-Member -type NoteProperty -name "Library Name" -value $List.Title -Force
  72. $resultsData | Add-Member -type NoteProperty -name "File Name" -value $ListItem.Name -Force
  73. $resultsData | Add-Member -type NoteProperty -name "File URL" -value $Web.Site.MakeFullUrl(“$($Web.ServerRelativeUrl.TrimEnd(‘/’))/$($ListItem.Url)”) -Force
  74. $resultsData | Add-Member -type NoteProperty -name "Last Modified" -value $ListItem['Modified'].ToString() -Force
  75. $resultsData | Add-Member -type NoteProperty -name "Checked-Out By" -value $ListItem.File.CheckedOutByUser -Force
  76. $resultsData | Add-Member -type NoteProperty -name "Checked-Out By User Email" -value $ListItem.File.CheckedOutBy.Email -Force
  77. $resultsData | Add-Member -type NoteProperty -name "Primary Administrator" -value $Site.Owner -Force
  78. $resultsData | Add-Member -type NoteProperty -name "Primary Administrator Email" -value $Site.Owner.Email -Force
  79. $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator" -value $Site.SecondaryContact -Force
  80. $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator Email" -value $Site.SecondaryContact.Email -Force
  81. $results += $resultsData
  82. }
  83. }
  84. }
  85. }
  86. $Web.Dispose()
  87. }
  88. $Site.Dispose()
  89. }
  90. $results | export-csv -Path $currentPhysicalPath/ListAllCheckedOutFiles.csv -notypeinformation -Force
  91. #Send message to output console
  92. write-host "Checked out Files Report Generated Successfully!"
  93. }
  94. catch [System.Exception]
  95. {
  96. write-host -f red $_.Exception.ToString()
  97. }
  98. }
  99. # Function Call
  100. $WebApp = Read-Host "Enter the web application URL to work on:"
  101. GetCheckedOutFiles $WebApp