Skip to content

Commit e07cdde

Browse files
author
Bob Pokorny
committed
Moved try/catch
1 parent 9981bec commit e07cdde

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

IISU/PSHelper.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,17 @@ private void InitializeRemoteSession()
351351

352352
_logger.LogInformation("Attempting to invoke PS-Session command on remote machine.");
353353

354-
var asyncResult = PS.BeginInvoke();
355-
if (!asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeoutSeconds)))
356-
{
357-
PS.Stop();
358-
throw new TimeoutException(
359-
$"Could not establish a remote PowerShell session to '{machineName}:{port}' within {timeoutSeconds} seconds. " +
360-
"Verify WinRM is reachable and the firewall allows the connection.");
361-
}
362-
363354
try
364355
{
356+
var asyncResult = PS.BeginInvoke();
357+
if (!asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeoutSeconds)))
358+
{
359+
PS.Stop();
360+
throw new TimeoutException(
361+
$"Could not establish a remote PowerShell session to '{machineName}:{port}' within {timeoutSeconds} seconds. " +
362+
"Verify WinRM is reachable and the firewall allows the connection.");
363+
}
364+
365365
_PSSession = new Collection<PSObject>(PS.EndInvoke(asyncResult));
366366
}
367367
catch (Exception ex)

0 commit comments

Comments
 (0)