Skip to content

Commit 230f9fe

Browse files
fix for bug #5171 (#5172)
Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent 3a5fc45 commit 230f9fe

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Commands/Base/DisconnectOnline.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ public class DisconnectOnline : BasePSCmdlet
1515
[Parameter(Mandatory = false)]
1616
public SwitchParameter ClearPersistedLogin;
1717

18+
private static readonly string[] sourceArray = ["stop", "ignore", "silentlycontinue"];
1819
protected override void ProcessRecord()
1920
{
21+
2022
if (PnPConnection.Current == null)
2123
{
22-
throw new InvalidOperationException(Properties.Resources.NoConnectionToDisconnect);
24+
// If the ErrorAction is not set to Stop, Ignore or SilentlyContinue throw an exception, otherwise just continue
25+
if (!sourceArray.Contains(ErrorActionSetting.ToLowerInvariant()))
26+
{
27+
throw new InvalidOperationException(Properties.Resources.NoConnectionToDisconnect);
28+
}
29+
else
30+
{
31+
return;
32+
}
2333
}
2434

2535
Environment.SetEnvironmentVariable("PNPPSHOST", string.Empty);
@@ -34,7 +44,7 @@ protected override void ProcessRecord()
3444
PnPConnection.Current.Certificate = null;
3545
}
3646

37-
if(ClearPersistedLogin)
47+
if (ClearPersistedLogin)
3848
{
3949
PnPConnection.ClearCache(PnPConnection.Current);
4050
}

0 commit comments

Comments
 (0)