2022-01-27 09:11:39 -05:00
function New-IcingaProgressStatus ( )
{
param (
2022-01-27 10:23:17 -05:00
[ string ] $Name = '' ,
[ int ] $CurrentValue = 0 ,
[ int ] $MaxValue = 1 ,
[ string ] $Message = 'Processing Icinga for Windows' ,
[ string ] $Status = '{0}% Complete' ,
[ switch ] $Details = $FALSE ,
[ switch ] $PrintErrors = $FALSE
2022-01-27 09:11:39 -05:00
) ;
if ( [ string ] :: IsNullOrEmpty ( $Name ) ) {
2022-01-27 10:23:17 -05:00
Write-IcingaConsoleError -Message 'Failed to create new progress status. You have to specify a name.' -DropMessage: $ ( -Not $PrintErrors ) ;
2022-01-27 09:11:39 -05:00
return ;
}
if ( $MaxValue -le 0 ) {
2022-01-27 10:23:17 -05:00
Write-IcingaConsoleError -Message 'Failed to create new progress status. The maximum value has to be larger than 0.' -DropMessage: $ ( -Not $PrintErrors ) ;
2022-01-27 09:11:39 -05:00
return ;
}
if ( $Global:Icinga . Private . ProgressStatus . ContainsKey ( $Name ) ) {
2022-01-27 10:23:17 -05:00
Write-IcingaConsoleError -Message 'Failed to create new progress status. A progress status with this name is already active. Use "Complete-IcingaProgressStatus" to remove it.' -DropMessage: $ ( -Not $PrintErrors ) ;
2022-01-27 09:11:39 -05:00
return ;
}
$Global:Icinga . Private . ProgressStatus . Add (
$Name ,
@ {
'CurrentValue' = $CurrentValue ;
'MaxValue' = $MaxValue ;
'Message' = $Message ;
'Status' = $Status ;
'Details' = ( [ bool ] $Details ) ;
}
) ;
$ProgressPreference = 'Continue' ;
}