Power Community

Power Community

Activate and Deactivate Features in SharePoint form 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 form Power Automate Flows Microsoft SharePoint, Microsoft Power Automate image 9

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.

Activate and Deactivate Features in SharePoint form Power Automate Flows Microsoft SharePoint, Microsoft Power Automate image 10

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 form Power Automate Flows Microsoft SharePoint, Microsoft Power Automate image 13

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Adjusting the time zone in Power BI DAX – Quick Tip

Hi Folks, Here is the use case, I was actually pulling data from Model Driven App. As I was testing...

More Articles Like This

- Advertisement -spot_img