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
Activate and Deactivate Features in SharePoint from Power Automate Flows 1

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
Activate and Deactivate Features in SharePoint from Power Automate Flows 2

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
Activate and Deactivate Features in SharePoint from Power Automate Flows 3

Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

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