function Wait-AlkamiServiceFabricClusterHealthy { <# .SYNOPSIS Polls the status of a Service Fabric cluster containing the specified host until either a timeout occurs or the cluster health status is 'Ok'. .PARAMETER Hostname [string] The host name of any server in the Service Fabric cluster. If not provided, defaults to localhost. .PARAMETER TimeoutMinutes [byte] The length of time in minutes to poll the cluster for a healthy status before declaring that an error has occurred. Defaults to 30 minutes. .PARAMETER SleepIntervalSeconds [byte] The length of time in seconds to pause between cluster status queries. Defaults to 15 seconds. #> [CmdletBinding()] param( [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [string]$Hostname = 'localhost', [Parameter(Mandatory=$false)] [byte]$TimeoutMinutes = 30, [Parameter(Mandatory=$false)] [ValidateRange(1, 120)] [byte]$SleepIntervalSeconds = 15 ) $loglead = (Get-LogLeadName) Connect-AlkamiServiceFabricCluster -Hostname $Hostname Write-Host "$loglead : Waiting for Service Fabric cluster to be healthy." # Keep looping until the Service Fabric cluster is healthy or we timeout. $stopwatch = [system.diagnostics.stopwatch]::StartNew() while($true) { $clusterHealth = Get-ServiceFabricClusterHealth if ( $clusterHealth.AggregatedHealthState -eq 'Ok' ) { $stopwatch.Stop() Write-Host "$logLead : Service Fabric cluster is healthy after $($stopwatch.Elapsed.ToString())." break } elseif ( $stopwatch.Elapsed.TotalMinutes -gt $timeoutMinutes ) { $stopwatch.Stop() Write-Error "$logLead : Timed out waiting for Service Fabric cluster to be healthy after $($stopwatch.Elapsed.ToString())." break } else { Start-Sleep -Seconds $sleepIntervalSeconds } } }