From e791bcf3e5032c51e183e83488d888b2e617798b Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Sat, 1 Nov 2025 13:56:25 +0000 Subject: [PATCH 1/2] Potential fix for bug #5145 to suppress any errors, e.g. if feature is already activated --- src/Commands/Features/EnableFeature.cs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Commands/Features/EnableFeature.cs b/src/Commands/Features/EnableFeature.cs index 4e58c1e96..4a7547d0f 100644 --- a/src/Commands/Features/EnableFeature.cs +++ b/src/Commands/Features/EnableFeature.cs @@ -20,15 +20,27 @@ public class EnableFeature : PnPWebCmdlet protected override void ExecuteCmdlet() { var pnpContext = Connection.PnPContext; - if (Scope == FeatureScope.Web) + + try { - pnpContext.Web.LoadAsync(w => w.Features).GetAwaiter().GetResult(); - pnpContext.Web.Features.EnableAsync(Identity).GetAwaiter().GetResult(); + if (Scope == FeatureScope.Web) + { + pnpContext.Web.LoadAsync(w => w.Features).GetAwaiter().GetResult(); + pnpContext.Web.Features.EnableAsync(Identity).GetAwaiter().GetResult(); + } + else + { + pnpContext.Site.LoadAsync(s => s.Features).GetAwaiter().GetResult(); + pnpContext.Site.Features.EnableAsync(Identity).GetAwaiter().GetResult(); + } } - else + catch (Exception ex) { - pnpContext.Site.LoadAsync(s => s.Features).GetAwaiter().GetResult(); - pnpContext.Site.Features.EnableAsync(Identity).GetAwaiter().GetResult(); + if (!Force.IsPresent) + { + throw new Exception(ex.Message); + } + // If Force is specified, suppress the exception } } } From 68c6d0e7581b28bb838b8884b70fb82fb8b25a14 Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Sat, 8 Nov 2025 12:33:55 +0000 Subject: [PATCH 2/2] Mark Force as obsolete and remove Force and Sandboxed parameters from documentation --- documentation/Enable-PnPFeature.md | 37 -------------------------- src/Commands/Features/EnableFeature.cs | 25 +++++------------ 2 files changed, 7 insertions(+), 55 deletions(-) diff --git a/documentation/Enable-PnPFeature.md b/documentation/Enable-PnPFeature.md index 00d6d223e..3f1269265 100644 --- a/documentation/Enable-PnPFeature.md +++ b/documentation/Enable-PnPFeature.md @@ -34,13 +34,6 @@ This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" ### EXAMPLE 2 ```powershell -Enable-PnPFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Force -``` - -This will enable the feature with the id "99a00f6e-fb81-4dc7-8eac-e09c6f9132fe" with force. - -### EXAMPLE 3 -```powershell Enable-PnPFeature -Identity 99a00f6e-fb81-4dc7-8eac-e09c6f9132fe -Scope Web ``` @@ -62,20 +55,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Force -Specifies whether to overwrite an existing feature with the same feature identifier. This parameter is ignored if there are no errors. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Identity The id of the feature to enable. @@ -90,20 +69,6 @@ Accept pipeline input: True (ByValue) Accept wildcard characters: False ``` -### -Sandboxed -Specify this parameter if the feature you're trying to activate is part of a sandboxed solution. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Scope Specify the scope of the feature to activate, either Web or Site. Defaults to Web. @@ -119,8 +84,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` - - ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) diff --git a/src/Commands/Features/EnableFeature.cs b/src/Commands/Features/EnableFeature.cs index 4a7547d0f..cc50e6fec 100644 --- a/src/Commands/Features/EnableFeature.cs +++ b/src/Commands/Features/EnableFeature.cs @@ -11,6 +11,7 @@ public class EnableFeature : PnPWebCmdlet [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] public Guid Identity; + [Obsolete("The Force parameter is obsolete and will be removed in future versions. Please update your scripts accordingly.")] [Parameter(Mandatory = false)] public SwitchParameter Force; @@ -20,27 +21,15 @@ public class EnableFeature : PnPWebCmdlet protected override void ExecuteCmdlet() { var pnpContext = Connection.PnPContext; - - try + if (Scope == FeatureScope.Web) { - if (Scope == FeatureScope.Web) - { - pnpContext.Web.LoadAsync(w => w.Features).GetAwaiter().GetResult(); - pnpContext.Web.Features.EnableAsync(Identity).GetAwaiter().GetResult(); - } - else - { - pnpContext.Site.LoadAsync(s => s.Features).GetAwaiter().GetResult(); - pnpContext.Site.Features.EnableAsync(Identity).GetAwaiter().GetResult(); - } + pnpContext.Web.LoadAsync(w => w.Features).GetAwaiter().GetResult(); + pnpContext.Web.Features.EnableAsync(Identity).GetAwaiter().GetResult(); } - catch (Exception ex) + else { - if (!Force.IsPresent) - { - throw new Exception(ex.Message); - } - // If Force is specified, suppress the exception + pnpContext.Site.LoadAsync(s => s.Features).GetAwaiter().GetResult(); + pnpContext.Site.Features.EnableAsync(Identity).GetAwaiter().GetResult(); } } }