From 78b7083700943009647be0c63a6ce985211a20db Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Tue, 25 Nov 2025 20:42:28 +0000 Subject: [PATCH] fix for bug #5171 --- src/Commands/Base/DisconnectOnline.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Commands/Base/DisconnectOnline.cs b/src/Commands/Base/DisconnectOnline.cs index 0bd2cce7c..545c23640 100644 --- a/src/Commands/Base/DisconnectOnline.cs +++ b/src/Commands/Base/DisconnectOnline.cs @@ -15,11 +15,21 @@ public class DisconnectOnline : BasePSCmdlet [Parameter(Mandatory = false)] public SwitchParameter ClearPersistedLogin; + private static readonly string[] sourceArray = ["stop", "ignore", "silentlycontinue"]; protected override void ProcessRecord() { + if (PnPConnection.Current == null) { - throw new InvalidOperationException(Properties.Resources.NoConnectionToDisconnect); + // If the ErrorAction is not set to Stop, Ignore or SilentlyContinue throw an exception, otherwise just continue + if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant())) + { + throw new InvalidOperationException(Properties.Resources.NoConnectionToDisconnect); + } + else + { + return; + } } Environment.SetEnvironmentVariable("PNPPSHOST", string.Empty); @@ -34,7 +44,7 @@ protected override void ProcessRecord() PnPConnection.Current.Certificate = null; } - if(ClearPersistedLogin) + if (ClearPersistedLogin) { PnPConnection.ClearCache(PnPConnection.Current); }