124909
Dec 21, 2015, updated at 11:11:03 (UTC)
1401
4
0
Powershell: Bestimmte Anzahl an Variablen von User Eingabe speichern
Morgen Freunde,
ich habe ein kleines Problem. Ich habe eine Do-Until-Schleife:
Nun möchte ich aber, dass $AnzahlHosts soviele Werte aufnehmen kann wie vorher in $AnzahlStandorte eingegeben wurde.
Ich vermute die Lösung wäre was in die Richtung Array.
Vielen Dank vorab!
ich habe ein kleines Problem. Ich habe eine Do-Until-Schleife:
$AnzahlStandorte = Read-Host Geben Sie die Anzahl der Standorte ein
$Variable = 0
Do {$AnzahlHosts = Read-Host Geben Sie die Anzahl der Hosts pro Standort ein;$Variable++} Until ($Variable -eq $AnzahlStandorte)
Nun möchte ich aber, dass $AnzahlHosts soviele Werte aufnehmen kann wie vorher in $AnzahlStandorte eingegeben wurde.
Ich vermute die Lösung wäre was in die Richtung Array.
Vielen Dank vorab!
Please also mark the comments that contributed to the solution of the article
Content-Key: 291456
Url: https://administrator.de/contentid/291456
Printed on: April 26, 2024 at 13:04 o'clock
4 Comments
Latest comment
[int]$AnzahlStandorte = Read-Host "Geben Sie die Anzahl der Standorte ein"
$anzahlhosts = @()
Do {
$AnzahlHosts += Read-Host "Geben Sie die Anzahl der Hosts pro Standort ein"
}
Until ($anzahlhosts.length -eq $AnzahlStandorte)
$anzahlhosts
Oder auch so mit einer Hashtable:
Frohes Fest
Gruß jodel32
[int]$AnzahlStandorte = Read-Host "Geben Sie die Anzahl der Standorte ein"
$hosts = [ordered]@{}
1..$AnzahlStandorte | %{
$hosts."Standort-$_" = Read-Host "Geben Sie die Anzahl der Hosts für Standort $_ ein"
}
$hosts
Gruß jodel32