124909

Powershell: Bestimmte Anzahl an Variablen von User Eingabe speichern

Morgen Freunde,

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!
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 291456

Url: https://administrator.de/forum/powershell-bestimmte-anzahl-an-variablen-von-user-eingabe-speichern-291456.html

Ausgedruckt am: 01.07.2025 um 23:07 Uhr

122990
Lösung 122990 21.12.2015 aktualisiert um 12:11:03 Uhr
Goto Top
[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
Gruß grexit
114757
114757 21.12.2015 aktualisiert um 11:41:09 Uhr
Goto Top
Oder auch so mit einer Hashtable:
[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
Frohes Fest
Gruß jodel32
124909
124909 21.12.2015 um 12:11:16 Uhr
Goto Top
Vielen Dank, dir auch!
124909
124909 21.12.2015 um 12:11:25 Uhr
Goto Top
Besten dank!