From 026ce5c915c2b4bccb1fabbd23691d4b371d84ba Mon Sep 17 00:00:00 2001 From: David Paulson Date: Thu, 10 Aug 2023 13:07:59 -0500 Subject: [PATCH] Allow Get-EventLogLevel to force reconnect with loop --- Shared/Confirm-ExchangeShell.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Shared/Confirm-ExchangeShell.ps1 b/Shared/Confirm-ExchangeShell.ps1 index 0c33725816..fc37ab484c 100644 --- a/Shared/Confirm-ExchangeShell.ps1 +++ b/Shared/Confirm-ExchangeShell.ps1 @@ -40,7 +40,14 @@ function Confirm-ExchangeShell { try { $currentErrors = $Error.Count - $eventLogLevel = Get-EventLogLevel -ErrorAction Stop | Select-Object -First 1 + $attempts = 0 + do { + $eventLogLevel = Get-EventLogLevel -ErrorAction Stop | Select-Object -First 1 + $attempts++ + if ($attempts -ge 5) { + throw "Failed to run Get-EventLogLevel too many times." + } + } while ($null -eq $eventLogLevel) $getEventLogLevelCallSuccessful = $true foreach ($e in $eventLogLevel) { Write-Verbose "Type is: $($e.GetType().Name) BaseType is: $($e.GetType().BaseType)"