Activate 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

Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

Leave a Reply

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

Discover more from SharePains

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

Continue reading