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-20T23:28:44.3266667+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,369 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,897 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,634 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,952 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AllenXu-MSFT 21,211 Reputation points Microsoft Vendor
    2024-11-21T06:06:50.39+00:00

    Hi @PVK Kapardhi,

    As said in this thread which is similar to yours: [BUG] Get-PnPSiteFileVersionBatchDeleteJobStatus as Function App Managed Identity -- Cannot Call this API w/ App Only principal, some cmdlets are not able to be called from app only access. You can report this issue to the dedicated PnP PowerShell forum here: https://github.com/pnp/powershell/issues or raise a ticket with Microsoft to let them help you check form the backend.

    Thanks.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.