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,
- To select the a web application to operate on
- To generate a report in CSV format, which will be helpful for excel reporting.
Business Case
S. No. | Business Case |
1 | Before 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
- SharePoint Application Developers
- SharePoint Administrator
- SharePoint Architect
Offerings
- One reusable PowerShell script is provided which needs to be run to get a list of Checked out files.
- Generate a report in excel format which includes information like
- Site Collection Title
- Site Collection URL
- Web Title
- Web URL
- Library Name
- File Name
- File URL
- Last Modified
- Checked-out By
- Checked-out By Email Address
- Primary Admin
- Primary admin Email
- Secondary Admin
- Secondary Admin Email
Technical Details
Below are the technical details for this PowerShell script,
- 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.
PowerShell Script
- ##########################################################################################################################
- ######## V 1.0
- ######## PowerShell Script to get a list of checked out files in your SharePoint Environment
- ################################################################################################################################
-
- #check to see if the PowerShell Snapin is added
- if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
- Add-PSSnapin Microsoft.SharePoint.PowerShell;
- }
-
- ## SharePoint DLL
- [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
- $global:currentPhysicalPath = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
-
- Function Get-SPWebApplication()
- {
- Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )
- return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
- }
-
- Function global:Get-SPSite()
- {
- Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )
-
- if($SiteCollURL -ne '')
- {
- return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)
- }
- }
-
- Function global:Get-SPWeb()
- {
- Param( [Parameter(Mandatory=$true)] [string]$SiteURL )
- $site = Get-SPSite($SiteURL)
- if($site -ne $null)
- {
- $web=$site.OpenWeb();
- }
- return $web
- }
- #EndRegion
-
- Function GetCheckedOutFiles([string]$WebAppURL)
- {
- try
- {
- $results = @()
-
- #Get the Web Application
- $WebApp=Get-SPWebApplication($WebAppURL)
-
- #Arry to Skip System Lists and Libraries
- $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates",
- "List Template Gallery", "Theme Gallery", "Reporting Templates", "Solution Gallery",
- "Style Library", "Web Part Gallery","Site Assets", "wfpub","Site Pages")
-
- #Loop through each site collection
- foreach($Site in $WebApp.Sites)
- {
- #Loop through each site in the site collection
- foreach($Web in $Site.AllWebs)
- {
- #Loop through each document library
- foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))
- {
- #Get only Document Libraries & Exclude Hidden System libraries
- if (($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )
- {
- #Loop through eadh Item
- foreach ($ListItem in $List.Items)
- {
- if( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))
- {
- $sitecollectionUrl = "<SiteCollection relativeURL=" + $Site.RootWeb.ServerRelativeURL + "></SiteCollection>"
- #Create an object to hold storage data
- $resultsData = New-Object PSObject
- $resultsData | Add-Member -type NoteProperty -name "SiteCollection Title" -value $Site.RootWeb.Title -Force
- $resultsData | Add-Member -type NoteProperty -name "SiteCollection URL" -value $sitecollectionUrl -Force
- $resultsData | Add-Member -type NoteProperty -name "Web Title" -value $Web.Title -Force
- $resultsData | Add-Member -type NoteProperty -name "Web URL" -value $Web.url -Force
- $resultsData | Add-Member -type NoteProperty -name "Library Name" -value $List.Title -Force
- $resultsData | Add-Member -type NoteProperty -name "File Name" -value $ListItem.Name -Force
- $resultsData | Add-Member -type NoteProperty -name "File URL" -value $Web.Site.MakeFullUrl(“$($Web.ServerRelativeUrl.TrimEnd(‘/’))/$($ListItem.Url)”) -Force
- $resultsData | Add-Member -type NoteProperty -name "Last Modified" -value $ListItem['Modified'].ToString() -Force
- $resultsData | Add-Member -type NoteProperty -name "Checked-Out By" -value $ListItem.File.CheckedOutByUser -Force
- $resultsData | Add-Member -type NoteProperty -name "Checked-Out By User Email" -value $ListItem.File.CheckedOutBy.Email -Force
- $resultsData | Add-Member -type NoteProperty -name "Primary Administrator" -value $Site.Owner -Force
- $resultsData | Add-Member -type NoteProperty -name "Primary Administrator Email" -value $Site.Owner.Email -Force
- $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator" -value $Site.SecondaryContact -Force
- $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator Email" -value $Site.SecondaryContact.Email -Force
- $results += $resultsData
- }
- }
- }
- }
- $Web.Dispose()
- }
- $Site.Dispose()
- }
- $results | export-csv -Path $currentPhysicalPath/ListAllCheckedOutFiles.csv -notypeinformation -Force
-
- #Send message to output console
- write-host "Checked out Files Report Generated Successfully!"
- }
- catch [System.Exception]
- {
- write-host -f red $_.Exception.ToString()
- }
- }
-
- # Function Call
- $WebApp = Read-Host "Enter the web application URL to work on:"
- GetCheckedOutFiles $WebApp