diff --git a/src/Commands/Base/ConnectOnline.cs b/src/Commands/Base/ConnectOnline.cs index 517aa0185..e4d52d727 100644 --- a/src/Commands/Base/ConnectOnline.cs +++ b/src/Commands/Base/ConnectOnline.cs @@ -304,6 +304,8 @@ public class ConnectOnline : BasePSCmdlet [Parameter(Mandatory = true, ParameterSetName = ParameterSet_OSLOGIN)] public SwitchParameter OSLogin; + private static readonly string[] sourceArray = ["stop", "ignore", "silentlycontinue"]; + protected override void ProcessRecord() { cancellationTokenSource = new CancellationTokenSource(); @@ -461,7 +463,7 @@ protected void Connect(ref CancellationToken cancellationToken) } // If the ErrorAction is not set to Stop, Ignore or SilentlyContinue throw an exception, otherwise just continue - if (!new[] { "stop", "ignore", "silentlycontinue" }.Contains(ErrorActionSetting.ToLowerInvariant())) + if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant())) { throw new PSInvalidOperationException(errorMessage); } @@ -1124,7 +1126,7 @@ private void ReuseAuthenticationManager() PnPConnection.CachedAuthenticationManager = contextSettings?.AuthenticationManager; } - private SecureString StringToSecureString(string inputString) + private static SecureString StringToSecureString(string inputString) { SecureString secPassword = new SecureString(); foreach (char ch in inputString) diff --git a/src/Commands/ContentTypes/AddContentType.cs b/src/Commands/ContentTypes/AddContentType.cs index aef7cbe20..83c8ae11c 100644 --- a/src/Commands/ContentTypes/AddContentType.cs +++ b/src/Commands/ContentTypes/AddContentType.cs @@ -1,5 +1,5 @@ -using System.Management.Automation; -using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client; +using System.Management.Automation; namespace PnP.PowerShell.Commands.ContentTypes @@ -23,7 +23,7 @@ public class AddContentType : PnPWebCmdlet public ContentType ParentContentType; [Parameter(Mandatory = false)] - public string DocumentTemplate; + public string DocumentTemplate; protected override void ExecuteCmdlet() { diff --git a/src/Commands/ContentTypes/AddContentTypeToList.cs b/src/Commands/ContentTypes/AddContentTypeToList.cs index 0b26ebbd6..ea10aa929 100644 --- a/src/Commands/ContentTypes/AddContentTypeToList.cs +++ b/src/Commands/ContentTypes/AddContentTypeToList.cs @@ -1,7 +1,6 @@ -using System.Management.Automation; -using Microsoft.SharePoint.Client; - +using Microsoft.SharePoint.Client; using PnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; namespace PnP.PowerShell.Commands.ContentTypes { diff --git a/src/Commands/ContentTypes/RemoveContentType.cs b/src/Commands/ContentTypes/RemoveContentType.cs index ff552da54..02203e820 100644 --- a/src/Commands/ContentTypes/RemoveContentType.cs +++ b/src/Commands/ContentTypes/RemoveContentType.cs @@ -1,7 +1,5 @@ -using System.Management.Automation; -using Microsoft.SharePoint.Client; - -using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; using Resources = PnP.PowerShell.Commands.Properties.Resources; namespace PnP.PowerShell.Commands.ContentTypes @@ -9,7 +7,6 @@ namespace PnP.PowerShell.Commands.ContentTypes [Cmdlet(VerbsCommon.Remove, "PnPContentType")] public class RemoveContentType : PnPWebCmdlet { - [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] public ContentTypePipeBind Identity; @@ -18,11 +15,10 @@ public class RemoveContentType : PnPWebCmdlet protected override void ExecuteCmdlet() { - var ct = Identity?.GetContentTypeOrThrow(nameof(Identity), CurrentWeb); - if (Force || ShouldContinue($"Remove Content Type '{ct.EnsureProperty(c => c.Name)}'?", Resources.Confirm)) + var ct = Identity?.GetContentTypeOrThrow(nameof(Identity), Connection.PnPContext); + if (Force || ShouldContinue($"Remove Content Type '{ct.Name}'?", Resources.Confirm)) { - ct.DeleteObject(); - ClientContext.ExecuteQueryRetry(); + ct.Delete(); } } } diff --git a/src/Commands/ContentTypes/RemoveContentTypeFromList.cs b/src/Commands/ContentTypes/RemoveContentTypeFromList.cs index 374634b39..d607f8dcd 100644 --- a/src/Commands/ContentTypes/RemoveContentTypeFromList.cs +++ b/src/Commands/ContentTypes/RemoveContentTypeFromList.cs @@ -1,11 +1,8 @@ -using System.Management.Automation; -using Microsoft.SharePoint.Client; - -using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Base.PipeBinds; +using System.Management.Automation; namespace PnP.PowerShell.Commands.ContentTypes { - [Cmdlet(VerbsCommon.Remove, "PnPContentTypeFromList")] public class RemoveContentTypeFromList : PnPWebCmdlet { @@ -19,13 +16,13 @@ public class RemoveContentTypeFromList : PnPWebCmdlet protected override void ExecuteCmdlet() { - var list = List.GetListOrThrow(nameof(List), CurrentWeb); + var list = List.GetListOrThrow(nameof(List), Connection.PnPContext); var ct = ContentType.GetContentTypeOrWarn(this, list); if (ct != null) { - CurrentWeb.RemoveContentTypeFromList(list, ct); + ct.Delete(); + list.Update(); } } - } } diff --git a/src/Commands/Features/DisableFeature.cs b/src/Commands/Features/DisableFeature.cs index d4ba8c34d..f91720748 100644 --- a/src/Commands/Features/DisableFeature.cs +++ b/src/Commands/Features/DisableFeature.cs @@ -1,8 +1,5 @@ using System; using System.Management.Automation; -using Microsoft.SharePoint.Client; - -using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Enums; namespace PnP.PowerShell.Commands.Features @@ -22,13 +19,16 @@ public class DisableFeature : PnPWebCmdlet protected override void ExecuteCmdlet() { + var pnpContext = Connection.PnPContext; if (Scope == FeatureScope.Web) { - CurrentWeb.DeactivateFeature(Identity); + pnpContext.Web.EnsureProperties(w => w.Features); + pnpContext.Web.Features.Disable(Identity); } else { - ClientContext.Site.DeactivateFeature(Identity); + pnpContext.Site.EnsureProperties(s => s.Features); + pnpContext.Site.Features.Disable(Identity); } } } diff --git a/src/Commands/Features/EnableFeature.cs b/src/Commands/Features/EnableFeature.cs index 98ee84773..bd22bb976 100644 --- a/src/Commands/Features/EnableFeature.cs +++ b/src/Commands/Features/EnableFeature.cs @@ -1,5 +1,4 @@ using System.Management.Automation; -using Microsoft.SharePoint.Client; using System; using PnP.PowerShell.Commands.Enums; @@ -9,7 +8,7 @@ namespace PnP.PowerShell.Commands.Features [OutputType(typeof(void))] public class EnableFeature : PnPWebCmdlet { - [Parameter(Mandatory = true, Position=0, ValueFromPipeline=true)] + [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] public Guid Identity; [Parameter(Mandatory = false)] @@ -20,13 +19,16 @@ public class EnableFeature : PnPWebCmdlet protected override void ExecuteCmdlet() { - if(Scope == FeatureScope.Web) + var pnpContext = Connection.PnPContext; + if (Scope == FeatureScope.Web) { - CurrentWeb.ActivateFeature(Identity); + pnpContext.Web.EnsureProperties(w => w.Features); + pnpContext.Web.Features.Enable(Identity); } else { - ClientContext.Site.ActivateFeature(Identity); + pnpContext.Site.EnsureProperties(s => s.Features); + pnpContext.Site.Features.Enable(Identity); } } } diff --git a/src/Commands/InformationManagement/GetLabel.cs b/src/Commands/InformationManagement/GetLabel.cs index 851f7a4c2..a7f417556 100644 --- a/src/Commands/InformationManagement/GetLabel.cs +++ b/src/Commands/InformationManagement/GetLabel.cs @@ -1,5 +1,4 @@ using System.Management.Automation; -using Microsoft.SharePoint.Client; using PnP.PowerShell.Commands.Base.PipeBinds; diff --git a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppProperties.cs b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppProperties.cs index 128a90b48..afec0f76a 100644 --- a/src/Commands/Model/PowerPlatform/PowerApp/PowerAppProperties.cs +++ b/src/Commands/Model/PowerPlatform/PowerApp/PowerAppProperties.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Globalization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; using System.Text.Json.Serialization; namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerApp diff --git a/src/Commands/Model/Teams/TeamsChannelFilesFolder.cs b/src/Commands/Model/Teams/TeamsChannelFilesFolder.cs index 1b7d961e5..3073f14c0 100644 --- a/src/Commands/Model/Teams/TeamsChannelFilesFolder.cs +++ b/src/Commands/Model/Teams/TeamsChannelFilesFolder.cs @@ -1,7 +1,4 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; +using System; namespace PnP.PowerShell.Commands.Model.Teams {