Activate and Deactivate Features in SharePoint from Power Automate FlowsActivate and Deactivate Features in SharePoint from Power Automate Flows

Enabling a SharePoint feature from a flow in Power Automate is easy, but how do you deactivate features?

Activate a feature in SharePoint

I’ve got a SharePoint site and I want to enable the Document ID Service feature. This is all simple.

_api/site/features/add('b50e3104-6812-424f-a011-cc90e6327318')

Using the above end point I can activate the feature. That GUID mentioned is the GUID for the Document ID Service feature.

Activate and Deactivate Features in SharePoint from Power Automate Flows

Deactivate Features in SharePoint

You might things that deactivating a feature is as easy as removing the feature.

_api/site/features/remove('b50e3104-6812-424f-a011-cc90e6327318')
Failed to deactivate feature in Sharepoint

But when I run this I get a Forbidden warning.

{"odata.error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}}}

clientRequestId: 0a85e720-d861-4788-b0eb-b25392b887b5
serviceRequestId: 35f1f9a0-4039-4000-832d-2539ec791a3d

While I do have the correct endpoint here.

Forbidden when disabling a SharePoint feature
Forbidden when disabling a SharePoint feature

Azure Automation and PnP Power Shell to the rescue

Within Azure Automation I create a runbook that runs the following code. Disabling and Enabling my feature using PnP.Powershell.

[CmdletBinding()]

param(
[OutputType([string[]])]

[Parameter(Mandatory=$true)]
[string]
$SiteURL,

[Parameter(Mandatory=$true)]
[string]
$FeatureId
)

Import-Module PnP.PowerShell

Connect-PnPOnline $SiteUrl -ManagedIdentity

Disable-PnPFeature -Identity $FeatureId
Enable-PnPFeature -Identity $FeatureId

Then In my flow I can add a Create job action as follows and I’m able to restart (or deactivate) my feature.

Activate and Deactivate Features in SharePoint from Power Automate Flows
Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading