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: Newest
  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?


  2. Jefferson Co 181 Reputation points
    2020-10-09T03:08:36.2+00:00

    Sorry accidentally clicked on 'Report a concern' I was trying to see if we can have a Teams chat or somehow a faster communication, I really appreciate the help but seems like it's not working as what you're showing me on your screen captures.

    Was this answer helpful?


  3. Jefferson Co 181 Reputation points
    2020-10-08T21:48:50.64+00:00

    Ok, so I used -UseWebLogin instead of cred because we do have 2FA enabled. Got past through that and another error message came up

    Get-PnPListItem : Cannot bind argument to parameter 'List' because it is null.
    At line:6 char:38

    • $allDocs = (Get-PnPListItem -List $list)
    • ~~~~~
    • CategoryInfo : InvalidData: (:) [Get-PnPListItem], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,PnP.PowerShell.Commands.Lists.GetListItem

    Was this answer helpful?


  4. Jefferson Co 181 Reputation points
    2020-10-08T20:07:55.477+00:00

    I think I'm getting progress. I used the script below

    $username = "correct_username"
    $password = "correct _password"
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
    Connect-PnPOnline -Url https://<site name> -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
                    print $doc.FieldValues.CheckoutUser.LookupValue
    
                }
            }
    

    Initially prompted me that Connect-PnPOnline is not recognized, I did "Install-Module -Name SharePointPowerShellOnline" and that resolved the Connect-PnPOnline not recognize issue but came up with

    Connect-PnPOnline : The sign-in name or password does not match one in the Microsoft account system.
    At line:1 char:1

    Does this has something to do with 2FA?

    Thanks
    Jeff

    Was this answer helpful?

    0 comments No comments

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.