Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/Commands/Features/EnableFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Loading