Script to list the checked out files from site collection

sns 9,236 Reputation points
2020-11-11T07:42:35.7+00:00

I want to pull the list of checked out documents from all the libraries in sharepoint site collection.
I should able to see in the report with library name and file name as well.

Please help.

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,941 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,031 Reputation points
    2020-11-12T02:20:28.463+00:00

    Hi @sns ,

    You could try the below script;

    $SiteUrl="http://sp13/sites/michael"  
    $Report="c:\report.csv"  
      
    #Get the site collection   
    $site=Get-SPSite $SiteUrl  
      
    #Write the CSV Header - Tab Separated  
    "Site Collection Name `t Site Name`t Library `t File Name `t File URL `t  Last Modified `t Checked-Out By" | Out-file $Report  
      
      
    #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  
    		if ($List.Hidden -eq $false){  
    			#Loop through each Item  
    			foreach($ListItem in $List.Items){  
    				If( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null)){  
    					#Log the data to a CSV file  
    					"$($Site.RootWeb.Title) `t $($Web.Title) `t $($List.Title) `t $($ListItem.Name) `t $($Web.Url)/$($ListItem.Url) `t  $($ListItem['Modified'].ToString()) `t  $($ListItem.File.CheckedOutByUser)" | Out-File $Report -Append  
    				}  
    			}  
    		}  
    	}  
    }	  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Sharath Kumar Aluri 3,071 Reputation points
    2020-11-11T15:25:47.15+00:00

    Below script will do for your requirement:

    #Add the PowerShell SnapIn 
    Add - PSSnapin microsoft.sharepoint.powershell 
    
    #Enter the Site Collection URL 
    $spWeb = Get - SPWeb "http://portal.globalsp.com/sites/sharatha/"
    
    #Function to get the CheckedOut items in document library    
    function GetCheckedItems($spWeb) { 
    
        Write-Host "Scanning Site: $($spWeb.Url)"
    
        foreach($list in ($spWeb.Lists | ? { $_ -is [Microsoft.SharePoint.SPDocumentLibrary] })) {  
            Write-Host "Scanning List: $($list.RootFolder.ServerRelativeUrl)"  
            foreach($item in $list.CheckedOutFiles) {  
                if (!$item.Url.EndsWith(".aspx")) { continue }  
                $writeTable = @{  
                    "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");  
                    "Checked Out By" = $item.CheckedOutBy;  
                    "Author" = $item.File.CheckedOutByUser.Name;  
                    "Checked Out Since" = $item.CheckedOutDate.ToString();  
                    "File Size (KB)" = $item.File.Length / 1000;  
                    "Email" = $item.File.CheckedOutByUser.Email;  
                }  
                New-Object PSObject -Property $writeTable  
            }  
            foreach($item in $list.Items) {  
                if ($item.File.CheckOutStatus -ne "None") {  
                    if (($list.CheckedOutFiles | where { $_.ListItemId -eq $item.ID }) -ne $null) { continue }  
                    $writeTable = @{  
                        "URL" = $spWeb.Site.MakeFullUrl("$($spWeb.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");  
                        "Checked Out By" = $item.File.CheckedOutByUser.LoginName;  
                        "Author" = $item.File.CheckedOutByUser.Name;  
                        "Checked Out Since" = $item.File.CheckedOutDate.ToString();  
                        "File Size (KB)" = $item.File.Length / 1000;  
                        "Email" = $item.File.CheckedOutByUser.Email;  
                    }  
                    New-Object PSObject -Property $writeTable  
                }  
            }  
        }  
        foreach($subWeb in $spWeb.Webs) {
    
            GetCheckedItems($subWeb)  
        }  
        $spWeb.Dispose()  
    }  
    GetCheckedItems($spWeb) | Out - GridView  
    # As an alternate option you can export the data to a textfile as well.Uncomment below code to do that  
    # GetCheckedItems($spWeb) | Out - File c: \CheckedOutItemsInSiteCollection.txt - width 300  
    

    Thanks & Regards,

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.