I want to create a dictionary, on which later on I would like to iterate. So the dictonary would look like this:
$dictionary =
subnet |address
xyz | 10.1.2.0/24
abc | 10.1.3.0/24
psh | 10.1.4.0/24
And i would like to iterate
foreach ($item in $dictionary){
$dmz = New-AzVirtualNetworkSubnetConfig -Name $item.subnet -AddressPrefix $item.address
}
Does anyone knows how to create such a dictionary/table? As i am not really familiar with powershell, but I would like to create a simple script
CodePudding user response:
I'd recommend using CSV data as they are the esiest to edit by hand
$dictionary =
@'
subnet,address
"xyz","10.1.2.0/24"
"abc","10.1.3.0/24"
"psh","10.1.4.0/24"
'@ |
ConvertFrom-Csv
foreach ($item in $dictionary) {
$dmz = New-AzVirtualNetworkSubnetConfig -Name $item.subnet -AddressPrefix $item.address
}
Of course you could use a CSV file and import it with Import-CSV
. This way you wouldn't need to edit the script itself. ;-)