124909
Goto Top

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!

Content-Key: 291456

Url: https://administrator.de/contentid/291456

Printed on: April 26, 2024 at 13:04 o'clock

Mitglied: 122990
Solution 122990 Dec 21, 2015 updated at 11:11:03 (UTC)
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
Mitglied: 114757
114757 Dec 21, 2015 updated at 10:41:09 (UTC)
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
Mitglied: 124909
124909 Dec 21, 2015 at 11:11:16 (UTC)
Goto Top
Vielen Dank, dir auch!
Mitglied: 124909
124909 Dec 21, 2015 at 11:11:25 (UTC)
Goto Top
Besten dank!