Based on the script from Technet(https://gallery.technet.microsoft.com/office/Find-all-checked-out-files-56fd562d) and the post above, we've succeeded in creating a script that does what we want: Search for files checked out by specific user, and check them despite of the view threshold.
There's a few variables that have to changed: URL, Username, password, library name (Title), and targetlogin (user to search for).
You must download Sharepoint client components for the script to work: https://www.microsoft.com/en-us/download/details.aspx?id=42038
#Paths to SDK
[Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location))
[Reflection.Assembly]::LoadFile(([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location))
#Enter the data
$url="https://company.sharepoint.com/sites/sitename/"
$username="[email protected]"
$password= "password" | ConvertTo-SecureString -AsPlainText -Force
$title="Library name"
$limit=200
$targetLogin = "[email protected]"
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
# Load the up list
$lookupList = $ctx.Web.Lists.GetByTitle($title)
$ctx.Load($lookupList)
# Prepare the query
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = '<View Scope="RecursiveAll"><RowLimit Paged="TRUE">1000</RowLimit></View>'
# An array to hold all of the ListItems
$items = @()
# Get Items from the List until we reach the end
do
{
$listItems = $lookupList.getItems($query)
$ctx.Load($listItems)
$ctx.ExecuteQuery()
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach($item in $listItems)
{
Try
{
# Add each item
#$items += $item
Write-Output $item["FileRef"]
$file = $ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
$ctx.Load($file)
$ctx.Load($file.Versions)
$ctx.Load($file.ListItemAllFields)
$ctx.Load($file.EffectiveInformationRightsManagementSettings)
$ctx.Load($file.Properties)
$ctx.Load($file.VersionEvents)
$CheckedOutByUser=$file.CheckedOutByUser
$ctx.Load($CheckedOutByUser)
Try
{
$ctx.ExecuteQuery(); #Pull the file
}
Catch [System.Exception]
{
#Ignore errors, eg "File not found"
}
#Do your operation here
if($CheckedOutByUser.LoginName -eq ("i:0#.f|membership|"+$targetLogin))
{
Write-Host "Check in: $file.Name "
Write-Host $CheckedOutByUser.LoginName
$file.CheckIn('Checked in automatically', 'MinorCheckIn')
#Do your checkin magic here
}
}
Catch [System.Exception]
{
# This shouldn't happen, but just in case
Write-Host $_.Exception.Message
}
}
}
While($query.ListItemCollectionPosition -ne $null)
#Write-Host ($items | Format-Table | Out-String)