Forum Discussion
CSOM challenge - SharePoint Online
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 script
.ItemCount shows 4 files
What I can see in UI
- Feb 03, 2017
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.
- Ali SalihFeb 03, 2017Iron Contributor
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.
- Feb 03, 2017
Can you check "Root Folder" under "Status Reports"?
- Ali SalihFeb 03, 2017Iron Contributor
I already used the SPCB. It doesn't see the files anywhere. ItemCount is reporting 4 there as well. But no files in sight.