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

PVK Kapardhi 0 Reputation points
2024-11-20T22:17:09.5433333+00:00

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

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,607 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,987 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,697 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,070 questions
0 comments No comments
{count} votes