Sorry for the delayed response. I tried the CSOM approach & it worked well in my dev & test tenants. But not working in PROD tenant. Any suggestions on this ?
I tried another option to use pnp instead of csom, it works fine to connect to the site & iterate the library documents. But i dont see any option to undeclare the record documents using pnp powershell and to get the client run time context using pnp.
Thanks in advance for your help on this issue.
$listname = 'ListName'
$Username = 'Email address removed'
$password = Read-Host -Prompt "Enter password" -AsSecureString
$url = 'https://abcsharepoint.com/sites/test'
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
[Microsoft.SharePOint.Client.ClientRuntimeContext] $runTimectx = [Microsoft.SharePOint.Client.ClientRuntimeContext] $ctx.Web.Context;
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$web = $ctx.Web;
$ctx.Load($web);
$ctx.Load($web.Webs);
$ctx.ExecuteQuery();
$listUpdate = $web.Lists.GetByTitle($listname)
$ctx.Load($listUpdate)
$ctx.ExecuteQuery()
#CAML Query to get all items inclusing sub-folders
$spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
$spQuery.ViewXml = "<View Scope='RecursiveAll' />";
$item = $listUpdate.GetItems($spQuery)
$ctx.Load($item)
$ctx.ExecuteQuery()
for($j=0; $j -lt $item.Count; $j++)
{
if($item[$j].FieldValues["_vti_ItemHoldRecordStatus"] -eq 273)
{
[Microsoft.SharePoint.Client.RecordsRepository.Records]::UndeclareItemAsRecord($runTimectx,$item[$j])
}
}
Error :
Exception calling "ExecuteQuery" with "0" argument(s): "The sign-in name or password does not match one in the Microsoft account system."
At line:12 char:9
+ $ctx.ExecuteQuery()