Choice 2
param(
[String] $userName,
[String] $passWord
)
$title = 'something'
$question = 'Are you sure you want to proceed?'
$choices = '&Yes', '&No'
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed'
} else {
Write-Host 'cancelled'
}
function GetStringValue([String]$title)
{
Write-Host $title
$inputString = Read-Host -prompt " -> Ohne Eingabe wird das Script abgebrochen!"
if ( ($inputString -eq $null) -or ($inputString -eq "") -or ($inputString -eq " ")) { return "" }
else { return $inputString }
}
function EnsureStringValueOrAbort([String]$ensureValue, [String]$title )
{
if ( -not $ensureValue ) {
Write-Host $title
$ensureValue = Read-Host -prompt " -> Ohne Eingabe wird das Script abgebrochen!"
if ( ($ensureValue -eq $null) -or ($ensureValue -eq "") -or ($ensureValue -eq " ")) {
Write-Host "cancelled"
exit 1
}
else { return $ensureValue }
}
}
function EnsureStringValueOrDefault([String]$ensureValue, [String]$defaultValue, [String]$title)
{
if ( -not $ensureValue ) {
Write-Host $title
$ensureValue = Read-Host -prompt " -> Ohne Eingabe wird der Defaultwert verwenden ($defaultValue)!"
if (($ensureValue -eq $null) -or ($ensureValue -eq "") -or ($ensureValue -eq " ")) { return $defaultValue }
else { return $ensureValue }
if ( -not $ensureValue ) {
Write-Host "cancelled"
exit 1}# Kein Wert also doch abbrechen
}
}
$passWord = EnsureStringValueOrAbort $passWord "Bitte geben Sie ein Passwort an."
Write-Host $passWord
$userName = EnsureStringValueOrDefault $userName "sa" "Bitte geben Sie einen Benutzername an."
Write-Host $userName