2024-03-04 11:30:02 -05:00
function Wait-IcingaWindowsScheduledTask ( )
{
param (
[ string ] $TaskName = 'Management Task' ,
[ string ] $TaskPath = '\Icinga\Icinga for Windows\' ,
[ int ] $Timeout = 180
) ;
[ int ] $TimeoutTicks = $Timeout * 1000 ;
while ( $TimeoutTicks -gt 0 ) {
2024-03-14 12:16:09 -04:00
$TaskStatus = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue ;
if ( $null -eq $TaskStatus ) {
return ;
}
2024-03-04 11:30:02 -05:00
if ( $TaskStatus . State -eq 'Ready' ) {
break ;
}
Start-Sleep -Milliseconds 500 ;
$TimeoutTicks - = 500 ;
}
if ( $TimeoutTicks -le 0 ) {
Stop-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath | Out-Null ;
Write-IcingaConsoleError 'The scheduled task "{0}" at path "{1}" could not be executed within {2} seconds and run into a timeout' -Objects $TaskName , $TaskPath , $Timeout ;
}
}