Wie kann ich eine Variablenbenennung mit fortlaufender Nummer generieren
Hallo.
Wie kann ich in Powershell eine Variablennamen erstellen der eine fortlaufende Nummer hat?
Variablenbenennung:
Var_1
Var_2
Var_3...
Gibt es hierfür eine Lösung?
Gruß
Christoph
Wie kann ich in Powershell eine Variablennamen erstellen der eine fortlaufende Nummer hat?
Variablenbenennung:
Var_1
Var_2
Var_3...
$counter=$counter
($var$counter)="$counter"
Gibt es hierfür eine Lösung?
Gruß
Christoph
Please also mark the comments that contributed to the solution of the article
Content-Key: 7915063402
Url: https://administrator.de/contentid/7915063402
Printed on: December 6, 2023 at 03:12 o'clock
4 Comments
Latest comment

Moin.
oder
Sowas ist in Powershell aber meist vollkommen überflüssig und verschwendet nur unnötig Speicher. Wenn du das doch willst kennst du wohl Arrays, Objekte oder Hashtables noch nicht
.
Gruß siddius
1..10 | %{
New-Variable -Name "var_$_" -Value $_
}
1..10 | %{
iex "`$var_$_ = $_"
}
Sowas ist in Powershell aber meist vollkommen überflüssig und verschwendet nur unnötig Speicher. Wenn du das doch willst kennst du wohl Arrays, Objekte oder Hashtables noch nicht
$array = "Hallo","Hallo2","Hallo3"
$array[0]
$array= @()
1..10 | %{
$array += "Hallo $_"
}
$array[0]
$array[1]
# ....
$hashtable = @{}
$hashtable.1 = 10
$hashtable.2 = 20
# .... ausgeben usw.
$hashtable.2
$obj = [pscustomobject]@{
Property1 = "MyValue1"
Property2 = "MyValue2"
}
$obj.Property1