Enabling a SharePoint feature from a flow in Power Automate is easy, but how do you deactivate features?
Activate a feature in SharePoint
Table of Contents
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.
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')
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.
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.