From df670b65e3228a8475d87ac03870d0eb164e4d8f Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Tue, 18 Jun 2024 21:56:57 +0300 Subject: [PATCH] Fix #3908: improve connection validation in ConnectOnline.cs --- src/Commands/Base/ConnectOnline.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Commands/Base/ConnectOnline.cs b/src/Commands/Base/ConnectOnline.cs index 6a62be0e9..3a79064c2 100644 --- a/src/Commands/Base/ConnectOnline.cs +++ b/src/Commands/Base/ConnectOnline.cs @@ -306,11 +306,14 @@ protected void Connect(ref CancellationToken cancellationToken) { credentials = Credentials.Credential; } - - if (PingHost(new Uri(Url).Host) == false) + + if (ValidateConnection) { - throw new PSArgumentException("Host not reachable"); - } + if (PingHost(new Uri(Url).Host) == false) + { + throw new PSArgumentException("Host not reachable"); + } + } if (AzureEnvironment == AzureEnvironment.Custom) {