I am trying to iterate the VM names and storing them in PSCustomObject and assign a subnet in order wise in output like the following: VM1 Subnet1 VM2 Subnet2 VM3 Subnet3 VM4 Subnet1 VM5 Subnet2 How to achieve this.
$csv = import-csv C:\ps\sample.csv
$myobject = foreach ($line in $csv){
if ($line.count -gt 0) {
for($i = 0; $i -lt $line.count; $i++){
$count = $i + 1
[pscustomobject]@{
VMName = $line.vmname+$count
Subnet = $line.subnet -split ',' | Get-Random
Sku = $line.sku
os = $line.os
}
}
}
}
$myobject
Thanks!
