有没有办法在哈希表中插入foreach循环。
这样的东西?
$vms = get-vm
foreach ($vm in $vms) {
$disks=Get-Vhd $vm.id
$hash = [ordered]@{
'VM<br>Name' = $vm.vmname
'State' = $vm.state
'Disk' = foreach ($disk in $disks) {$disks.size -join '.' }
}
New-Object -TypeName PSObject -Property $hash
答案 0 :(得分:1)
$data = foreach ($disk in $disks) {$disks.size -join '.' }
$hash = [ordered]@{
'VM<br>Name' = $vm.vmname
'State' = $vm.state
'Disk' = $data
}