I have poured over a ton of posts and code and none seem to work with checked out files and really large lists. I am newish to sharepoint, especially online. I moved a doc repo up there for testing and no search results because everything is checked out. My lists have 780k files and 190k files, so well over the 5k crippling limitations. On the sharepoint side, the views work but no search as I am using the document center. Anyways, already loaded 2 different sub sites with meta data. I have required fields. I turned off versioning and went to classic view on 1 site, which is a clone of the other site but with tiff files bundled into PDFs.
I am trying to use some powershell (or c# via command line app) to check in the documents. The program works fine using CAML and RowLimit and paging the results, but I can't get just the checked out files because of the stuipid 5k limits. I can get the whole list and iterate through fine, but if the app hangs, which it hasn't, I have to start the whole process over. Would be great to just have the still checked out files.
I will post all the code, because I found it all over the Internets anyway.
function Get-SPOFolderFiles
{
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
[string]$Url,
[Parameter(Mandatory=$true,Position=3)]
$password,
[Parameter(Mandatory=$true,Position=4)]
[string]$ListTitle
)
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
Write-Host "Logged into Sharepoint"
$ll=$ctx.Web.Lists.GetByTitle( $ListTitle)
$ctx.Load($ll)
$ctx.ExecuteQuery()
## Page Position
$page = $null
## All Items
#$spqQuery.ViewXml="<View Scope='FilesOnly'><RowLimit>1000</RowLimit> </View>"
$qCommand = @"
<View Scope="RecursiveAll">
<Query>
<OrderBy>
<FieldRef Name='ID' Ascending='TRUE'/>
</OrderBy>
</Query>
<RowLimit Paged="TRUE">1000</RowLimit>
</View>
"@
$caml = @"
<OrderBy>
<FieldRef Name='ID' Ascending='TRUE'/>
</OrderBy>
"@
# <Where>
# <Geq>
# <FieldRef Name="CheckoutUser" LookupId="TRUE" />
# <Value Type="int">0</Value>
# </Geq>
# </Where>
#<FieldRef Name='Deal_x0023_' Ascending='TRUE'/>
# <Where>
# <IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull>
# </Where>
#<OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
# <IsNotNull><FieldRef Name='ID' /></IsNotNull>
# <IsNotNull><FieldRef Name='CheckoutUser' /></IsNotNull>
# <Eq><FieldRef Name='CheckoutUser' /><Value Type='Integer'><UserID Type='Integer' /></Value></Eq>
# <Where>
# <Lt><FieldRef Name="Deal_x0023_" /><Value>"a"</Value></Lt>
# </Where>
#<And><IsNotNull><FieldRef Name="CheckoutUser"/></IsNotNull></And>
Do{
$spqQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$spqQuery.ListItemCollectionPosition = $page
#$spqQuery.ViewAttributes = "Scope='Recursive'";
#$spqQuery.RowLimit = 100
#$spqQuery.Query = $caml
$spqQuery.ViewXml = $qCommand
$itemki=$ll.GetItems( $spqQuery)
$ctx.Load($itemki)
$ctx.ExecuteQuery()
## Getting the position of the previous page
$page = $itemki.ListItemCollectionPosition
Write-Host "################## PAGE " $page.PagingInfo " #########################"
Write-Host "processing query results. Recs: " + $itemki.Count
$Counter = 0;
foreach($item in $itemki)
{
$Counter++
Write-Host $Counter - $item["FileRef"] $item.ElementType
$file = $ctx.Web.GetFileByServerRelativeUrl($item["FileRef"]);
$ctx.Load($file)
$ctx.Load($file.Versions)
$ctx.Load($file.ListItemAllFields)
$Author=$file.Author
$CheckedOutByUser=$file.CheckedOutByUser
$LockedByUser=$file.LockedByUser
$ModifiedBy=$file.ModifiedBy
$ctx.Load($Author)
$ctx.Load($CheckedOutByUser)
$ctx.Load($LockedByUser)
$ctx.Load($ModifiedBy)
#$ctx.Load($file.EffectiveInformationRightsManagementSettings)
#$ctx.Load($file.Properties)
#$ctx.Load($file.VersionEvents)
try
{
$ctx.ExecuteQuery()
}
catch
{}
if($CheckedOutByUser.LoginName -ne $null){
Write-Host "File Name" $file.Name
Write-Host "Checked out by" $CheckedOutByUser.LoginName
$file.CheckIn('Checked in automatically', 'MajorCheckIn')
$ctx.Load($file)
try
{
$ctx.ExecuteQuery()
Write-Host $file.Name " has been checked in" -ForegroundColor DarkGreen
}
catch [Net.WebException]
{
Write-Host $_.Exception.ToString()
}
}
}
}
Until($page -eq $null)
}
and gets called like:
#Add required references to SharePoint client assembly to use CSOM
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
#Enter the data
$spPassword ="a password that is super duper secure"
$secureStringPwd = ConvertTo-SecureString -string $spPassword –asplaintext –force
#$AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString
$username="[email protected]"
$Url="https://aCompany.sharepoint.com/DocManage/PDFRepo/"
#$Url="https://aCompany.sharepoint.com/DocManage/TiffRepo/"
$ListTitle="Documents"
Get-sPOFolderFiles -Username $username -Url $Url -password $secureStringPwd -ListTitle $ListTitle