mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
53 lines
1.3 KiB
PowerShell
53 lines
1.3 KiB
PowerShell
function Get-IcingaAgentInstallerAnswerInput()
|
|
{
|
|
param(
|
|
$Prompt,
|
|
[ValidateSet("y", "n", "v")]
|
|
$Default,
|
|
$DefaultInput = '',
|
|
[switch]$Secure
|
|
);
|
|
|
|
$DefaultAnswer = '';
|
|
|
|
if ($Default -eq 'y') {
|
|
$DefaultAnswer = ' (Y/n)';
|
|
} elseif ($Default -eq 'n') {
|
|
$DefaultAnswer = ' (y/N)';
|
|
} elseif ($Default -eq 'v') {
|
|
if ([string]::IsNullOrEmpty($DefaultInput) -eq $FALSE) {
|
|
$DefaultAnswer = [string]::Format(' (Defaults: "{0}")', $DefaultInput);
|
|
}
|
|
}
|
|
|
|
if (-Not $Secure) {
|
|
$answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer));
|
|
} else {
|
|
$answer = Read-Host -Prompt ([string]::Format('{0}{1}', $Prompt, $DefaultAnswer)) -AsSecureString;
|
|
}
|
|
|
|
if ($Default -ne 'v') {
|
|
$answer = $answer.ToLower();
|
|
|
|
$returnValue = 0;
|
|
if ([string]::IsNullOrEmpty($answer) -Or $answer -eq $Default) {
|
|
$returnValue = 1;
|
|
} else {
|
|
$returnValue = 0;
|
|
}
|
|
|
|
return @{
|
|
'result' = $returnValue;
|
|
'answer' = '';
|
|
}
|
|
}
|
|
|
|
if ([string]::IsNullOrEmpty($answer)) {
|
|
$answer = $DefaultInput;
|
|
}
|
|
|
|
return @{
|
|
'result' = 2;
|
|
'answer' = $answer;
|
|
}
|
|
}
|