A community member has associated this post with a similar question:
Set-PnPSiteVersionPolicy for thousands of sites in SharePoint Online - Cannot call this API with an app-only principal
Only moderators can edit this content.
Set-PnPSiteVersionPolicy for thousands of sites in SharePoint Online - Cannot call this API with an app-only principal
We have 5000+ SharePoint Online sites in our tenant where i have to change the Site Version setting to automatic for all existing document libraries.
I am using the below to connect using an Azure App and i get the error "Cannot call this API with an app-only principal."
When i use either -Interactive or -UseWebLogin for a single site, it does that job but i cannot login in to each site for 5000+ times. What is the solution here?
The Azure App has all the necessary permissions both from SharePoint Online (AllSites.FullControl - Delegated, Sites.FullControl.All - Application) and Graph API (Sites.FullControl.All) Perspective.
Connect-PnPOnline -Url $TenantURL -ClientID $ClientID -Tenant $TenantID -CertificateBase64Encoded $Cert
Set-PnPSiteVersionPolicy -EnableAutoExpirationVersionTrim $true -ApplyToExistingDocumentLibraries