Forum Discussion
Dhi_V1800
Mar 28, 2022Copper Contributor
SharePoint online CSOM authentication fails in prod works in dev and test tenants
Hi, I tried the below csom script to undeclare all the existing records in a sharepoint online library. It works fine in dev and test tenants but fails in the production tenant. Any suggestions t...
Dhi_V1800
Mar 29, 2022Copper Contributor
As i said in my initial post i already tried this option and it is working to connect using pnp & to iterate the document.
But it doesnt have an option to undeclare record using pnp, also to use the csom code i need to client run time context. so stuck there.
Thanks
Kevin_Morgan
Mar 31, 2022Iron Contributor
We can use the OfficeDevPnP.Core assembly in PowerShell to create a SharePointContext object with different authentication types (ex: MFA). You can refer to this post : https://morgantechspace.com/2021/09/connect-to-sharepoint-site-with-mfa-account-using-csom-and-powershell.html
Try the below commands.
#Add required references to OfficeDevPnP.Core and SharePoint client assembly
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.29.2101.0\OfficeDevPnP.Core.dll")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$siteURL = "https://contoso.sharepoint.com/sites/siten_name"
$AuthenticationManager = new-object OfficeDevPnP.Core.AuthenticationManager
$ctx = $AuthenticationManager.GetWebLoginClientContext($siteURL)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
Write-Host "Title: " $ctx.Web.Title -ForegroundColor Green
Write-Host "Description: " $ctx.Web.Description -ForegroundColor Green