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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,730 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,535 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    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 = "amos@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.

    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-07T22:12:48.43+00:00

    I did run both cmdlets

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    Add-PSSnapin Microsoft.SharePoint.PowerShell

    But both showed 'No Snap-ins have been registered

    I tried installing both as well

    Install-Module -Name Microsoft.Online.SharePoint.PowerShell -RequiredVersion 16.0.8414.1200

    Import-Module Microsoft.Online.SharePoint.Powershell -Verbose

    Same issue


  2. 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

    0 comments No comments

  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

  4. 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.


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.