SharePoint Online: Manage Files Which Have No Checked in Version using PowerShell

When users don't provide value for mandatory metadata field values when uploading files (in classic experience) or when users forget to check in documents while the "Require Check Out" option under versioning settings of any library is set to "Yes", then those files are called "Files Which Have No Checked in Version", The file(s) which are uploaded will be stored on SharePoint but will be check out and visible only to the uploader! Often happens when users upload using File explorer view!

Manage Files Which Have No Checked In Version in SharePoint Online:
As a site administrator, You can take ownership of files which have no checked in version. To take control,
  • Go to "Manage files which have no checked in version" link under Library Settings, 
  • Select the documents and click on the "Take Ownership of Selection" button and confirmthe prompt. 
  • Once you took the ownership, the document gets removed from this page and starts appearing in the list where they are uploaded (only to You, until you check in them!) As a site owner, you can set the metadata properties if needed, check in and make these documents visible for all users . sharepoint online manage files which have no checked in version powershell
PowerShell to Take Ownership and Check-In All Files Which Have No Checked In Version in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set parameter values
$ListName ="Documents"

    #Get Credentials to connect
    $Cred= Get-Credential
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get Checked out Files with no checked in version
    $List = $Ctx.Web.lists.GetByTitle($ListName)
    $CheckedOutFiles = $List.GetCheckedOutFiles()

    #Loop through each checked-out file
    ForEach($File in $CheckedOutFiles)
        #Take Ownership of the File

        #Get the File and Check-in
        $CheckInFileURL = [String]::Concat($List.ParentWebUrl, $File.ServerRelativePath.DecodedUrl.Replace($List.ParentWebUrl, ""))
        $CheckInFile = $Ctx.web.GetFileByServerRelativeUrl($CheckInFileURL)

        #Check in the file
        $CheckInFile.CheckIn("Checked-in from PowerShell",[Microsoft.SharePoint.Client.CheckinType]::MajorCheckIn)

        Write-Host -f Yellow "'$($' at $($CheckInFile.ServerRelativeUrl) was Checked Out by: $($CheckedOutByUser.Email)"
        Write-host -f Green "Checked In The File Successfully!"         
Catch {
        write-host -f Red "Error:" $_.Exception.Message
Can I take ownership & Check-in of all Files from a specific user? Sure:
#Get the User
$User = $Web.EnsureUser("[email protected]");

#Check if the File is checked out to the specific user
If($File.CheckedOutById -eq $User.Id)
 #Take ownership and check-in

PnP PowerShell to Check-in All Checkedout Files with No Checked-In Version 
This PowerShell script checks in all files checked out to a particular user.
#Set Parameters
$SiteURL = ""
$ListName = "Branding"
$UserID = "i:0#.f|membership|[email protected]"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -UseWebLogin
$Ctx = Get-PnPContext

#Get the List
$List = Get-PnPList $ListName
#Get the User
$CheckedoutByUser = Get-PnPUser -Identity $UserID

#Get All Checked-Out Files
$CheckedOutFiles = $List.GetCheckedOutFiles()

#Check-in All Files Checked out to the User
$CheckedOutFiles | ForEach-Object {
    If($_.CheckedOutById -eq $CheckedoutByUser.Id)
        #Take over the Checked-Out File

        #Check-in the file
        $CheckInFileURL = [String]::Concat($List.ParentWebUrl, $_.ServerRelativePath.DecodedUrl.Replace($List.ParentWebUrl, ""))
        Set-PnPFileCheckedIn -Url $CheckInFileURL -CheckinType MajorCheckIn -Comment "Checked-In by the Script at $(Get-Date)"    
        Write-Host "Check-in the File: $CheckInFileURL"    


  1. Great article!
    But, we have a couple of questions.

    1) We're getting this error after running through the script once
    "Error Adding Custom Action! Exception calling "ExecuteQuery" with "0" argument(s): "File Not Found.""

    2) Where would we add the "Specific User" code?

  2. Hello! Amazing article, but is there a way to do all this via sharepoint-pnp?

    1. Updated the article with PnP PowerShell script!

  3. Hello,

    Tried using the PnP script. Worked well for small libraries but gives me the view threshold error for large document libraries.
    Is there a way to work around that?

    1. Im having the same problem

      Any chance the script can be updated to take this into account?

      Many thanks

    2. Unfortunately, The "GetCheckedOutFiles" method strictly complies with the 5000 threshold limit as of today.

    3. The only way to report on GetCheckedOutFiles in a large list/library is to scrape the page or check it every X days? thx!

  4. I have 300 sites to do this on, all in the same "Shared Documents" library, how can I import CSV of sites and loop through each site and apply the PnP script?


Please Login and comment to get your questions answered!

Powered by Blogger.