CSOM challenge - SharePoint Online

Iron Contributor
Hey community.

Do you know a way to access file objects that you can see in UI under Library Settings -> "Manage files that have no checked in version" in a SharePoint Online doc. lib via PowerShell ?

I spent couple hours and can't seem to access them via CSOM. I have couple files that I need to check-in like that but I am failing to accomplish.
8 Replies

Hi,

 

Check the below script. To check files for "Manage files that have no checked in version", you need to use the condition : 

$file.MajorVersion -eq "1" -and $file.Level -eq "Checkout"

 

This script uses SPO PnP also.

 

$cred=Get-Credential
$UName=$cred.UserName.ToString()
$Pass =$cred.GetNetworkCredential().Password
$SiteURL = "https:// tenantname.sharepoint.com/sites/testsite2"
$DocLibName = "Documents"

connect-pnponline -Url $SiteURL -Credentials $cred

$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$Password = $Pass | ConvertTo-SecureString -AsPlainText -Force

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UName,$Password)
$Context.Credentials = $Creds
#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.ExecuteQuery()

$Allfiles= $List.RootFolder.Files
$Context.Load($Allfiles)
$Context.ExecuteQuery()
foreach( $file in $Allfiles){

If($file.MajorVersion -eq "1" -and $file.Level -eq "Checkout")
{
Set-PnPFileCheckedIn -Url $file.ServerRelativeUrl
Write-Host $file.Name "Checked-in "
}
} 

@NarasimaPerumal Chandramohan Thanks for the attempt, however it doesn't work. It doesn't show ANY files although I can see files in the UI. These files are uploaded by someone else besides me, but never fully checked-in in the first place. There is no 'version'.  So $file.MajorVersion -eq "1" -and $file.Level -eq "Checkout" isn't a valid condition. Please see screenshots below.

 

1) Need to find where these files are located, and be able to load them up into the context

2) I need to take over the ownership with a similar method to on-premises SPCheckedOutFile.TakeOverCheckOut method. But that method doesn't exists because SPCheckedOutFile class doesn't exist in CSOM as far as I can see

 

Testing the scriptTesting the script

.ItemCount shows 4 files.ItemCount shows 4 files

What I can see in UIWhat I can see in UI

Hi,

 

Please download the below codeplex project[SharePoint Online Client Browser] and check the properties of the files that you are refering and then you change the script accordingly.

 

https://spcb.codeplex.com/

I already used the SPCB. It doesn't see the files anywhere. ItemCount is reporting 4 there as well. But no files in sight.

2017-02-03_7-23-28.png

 

 

@NarasimaPerumal Chandramohan I already used SharePoint Online Client Browser, and there are no files to be found. ItemCount shows 4 there as well, but Item are 0.

 

4 files do not show anywhere.4 files do not show anywhere.

Can you check "Root Folder" under "Status Reports"?

@NarasimaPerumal Chandramohan I did. Here is the screenshot.

Items are not shown.Items are not shown.

Anyone else ?