1

Is there a way in PowerShell to check in mass of files uploaded by other user in bulk at SharePoint Online?

I have a customer who has uploaded to a document library about 1500 files which do not have checked in version. The standard "Manage files which have no checked in version" page is hanging or loading way too long to when trying to handle this through UI. The document library in total has about 15000 documents at the moment so the list view threshold is also causing some limitations on what can be done.

1

You can use SharePoint Online PowerShell and CSOM to achieve it.

Two TechNet blogs for your reference:
Find all checked out files in SharePoint Online library and check them in

SharePoint Online: Get all checked-out files using Powershell

Note: when you use CSOM in your PowerShell script, the script requires SharePoint Online SDK.

  • Thanks. This might work but I still need to work around that pesky list view threshold as every PS script I've tried falls on that. – Kim B Oct 20 '17 at 10:17
1

Hope it helps someone (not perfect, but it helps).

$position = $null

do
{
$spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$spQuery.ListItemCollectionPosition = $position

$spQuery.ViewXml = '<View Scope="RecursiveAll"><RowLimit Paged="TRUE">1000</RowLimit></View>'

$listItem1 = $inList.GetItems($spQuery);
$Context.Load($listItem1)
$Context.ExecuteQuery()

Write-Host $listItem1.Count

$position = $listItem1.ListItemCollectionPosition


    foreach ($checkedOutListItem in $listItem1)
    {
        $Context.Load($checkedOutListItem.File)
        $Context.Load($checkedOutListItem.File.ListItemAllFields)
        $CheckedOutByUser=$checkedOutListItem.File.CheckedOutByUser
        $Context.Load($CheckedOutByUser)
        $Context.ExecuteQuery()

        Write-Host $CheckedOutByUser.LoginName

        if ($CheckedOutByUser.LoginName -ne $null)
        {
            $checkedOutListItem.File.CheckIn("CheckIn","MajorCheckIn")
            $Context.ExecuteQuery()
        }           
    }

$position = $listItem1.ListItemCollectionPosition

}Until($position -eq $null) 
0

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="administrator@domain.onmicrosoft.com"
$password= "password" | ConvertTo-SecureString  -AsPlainText -Force
$title="Library name"
$limit=200

$targetLogin = "administrator@domain.onmicrosoft.com"

$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)

protected by Community Jun 13 at 21:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.