Forum Discussion
Rollback Script for Purview Auto Labels Using PnP/Graph – Anyone Done This?
Hi ,
I have been working on a rollback script using PnP and Microsoft Graph API to remove a sensitivity label from SharePoint and OneDrive documents through an Enterprise App (service principal).
The purpose of this is to avoid a common issue in Purview. When a sensitivity label is applied through auto labeling and later changed manually, Purview reclassifies it as a manual label. After that, even if you run another scan, Purview will not automatically apply an auto label again because the file is now considered to have a user applied label.
To prevent this problem, the idea is to make all label changes through a service principal so that the change is not treated as a manual action. This gives us a safe way to roll back labels if something goes wrong and lets us return the files to a clean state so that Purview can apply auto labeling again when needed.
This approach would be very helpful during testing or when adjusting label priorities or scopes.
My question is the following:
Has anyone successfully built something like this?
I am looking for examples of removing labels in bulk or replacing one label with another, for example replacing Label A with Label B, using PnP or Graph through a service principal.
I do have a script somewhat ready but , I am also getting an error when calling some Graph endpoints that says the operation requires a Premium Purview feature (PAYG). If anyone has found a workaround or can confirm which operations require payment, that would be extremely helpful.
Thanks!
1 Reply
- milgo
Microsoft
Hello and thanks for reaching out.
I would expect this error because some Microsoft Graph APIs are metered. Label assignment/removal for SharePoint and OneDrive via Graph uses protected (metered) APIs such as assignSensitivityLabel, which require enabling metered APIs and linking the app to an Azure subscription (PAYG). This is explicitly a paid, premium capability. Here is an overview of metered APIs
Assign Sensitivity Label is mentioned as a Metered API