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
14 changes: 12 additions & 2 deletions src/Commands/Base/DisconnectOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -34,7 +44,7 @@ protected override void ProcessRecord()
PnPConnection.Current.Certificate = null;
}

if(ClearPersistedLogin)
if (ClearPersistedLogin)
{
PnPConnection.ClearCache(PnPConnection.Current);
}
Expand Down
Loading