Search for Check-In and Check out files in Sharepoint Document Library

Jefferson Co 181 Reputation points
2020-10-06T07:50:32.963+00:00

Hi,

We have a customer who doesn't have a file server and their only file storage is Microsoft SharePoint. One of their staff is having a hard time monitoring the files whether they're Check-In or Check-out. Made my research and found a set of cmdlets on how to do this but for some reason every time I type in the comdlet 'Get-SPWeb', it doesn't recognized and every time I typed in Add-snap-ins Microsoft.Sharepoint.Powershell shows 'No snap-ins have been registered.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Variables

$WebURL="http://sharepoint.crescent.com"
$LibraryURL="/Shared%20Documents" #Relative URL

Get Objects

$Web = Get-SPWeb $WebURL
$Folder = $web.GetFolder($LibraryURL)

Function to find all checked out files in a SharePoint library

Function CheckIn-CheckedOutFiles($Folder)
{

$Folder.Files | Where { $_.CheckOutStatus -ne "None" }  | ForEach-Object {
write-host ($_.Name,$_.URL,$_.CheckedOutBy)

#To Check in
$_.Checkin("Checked in by Administrator")
}

Process all sub folders

$Folder.SubFolders | ForEach-Object {
CheckIn-CheckedOutFiles $_
}
}

Call the function to find checkedout files

CheckIn-CheckedOutFiles $Folder

Read more: https://www.sharepointdiary.com/2013/02/find-all-checked-out-files-and-check-in.html#ixzz6a4c5K5FP

Thanks
Jeff

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author
Amos Wu-MSFT 4,131 Reputation points Moderator
2020-10-07T02:45:40.833+00:00

The script you shared can run normally in my environment.
30428-image.png
The way to solve "The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet, function" PowerShell error is to add

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  

More reference:
https://global-sharepoint.com/powershell/how-to-fix-the-the-term-get-spweb-is-not-recognized-as-the-name-of-a-cmdlet-function-powershell-error/
If you are using SharePoint Online,you could referto this blog:
https://social.technet.microsoft.com/wiki/contents/articles/34215.sharepoint-online-get-all-checked-out-files-using-powershell.aspx


Updated------------------------------

$username = "******@contoso.onmicrosoft.com"  
$password = "Password"  
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)  
Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred  
$list=Get-PnPList "lib"  
$allDocs = (Get-PnPListItem -List $list)   

        foreach ($doc in $allDocs) {  
            if ($null -ne $doc.FieldValues.CheckoutUser.LookupValue) {  
                write-host $doc.FieldValues.FileRef  
                Set-PnPFileCheckedIn -Url $doc.FieldValues.FileRef  
            }  
        }  

If the response 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.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Jefferson Co 181 Reputation points
    2020-10-12T17:44:47.48+00:00

    I think I know what's wrong. So It didn't give me results so I modified the script further more, until I got an error message saying

    The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.

    So I added

    $allDocs = (Get-PnPListItem -List $list -PageSize 500) to be honest not sure what this does just saw from an article and it worked, listed out a bunch of Check Out files.

    Thanks for the help
    Jeff

    Was this answer helpful?


Your answer

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