PowerCLI- 在 1 table 中获取 VM cd-mount
PowerCLI- get VM cd-mount in 1 table
我尝试将所有安装了 CD 的虚拟机集中到一个 table,但我得到的输出是一行一行的,如:
vm1
\vm1_isopath\
虚拟机2
\vm2_isopath\
是否可以获取 1 table 中包含 2 列虚拟机名称和 ISOPath 的所有信息?
我的代码是:
$VMs=Get-VM
ForEach ( $vm in $VMs)
{
$VMmount=Get-CDDrive -VM $vm
if ($VMmount.IsoPath)
{
$vm | select Name
$VMmount.IsoPath
}
}
谢谢。
我将您的代码扩展为:
$VMs=Get-VM
$vmInfos = @()
ForEach ( $vm in $VMs)
{
$VMmount=Get-CDDrive -VM $vm
if ($VMmount.IsoPath)
{
# Store needed info in hashtable
$info = @{}
$info.name = ($vm | select -ExpandProperty Name)
$info.IsoPath = $VMmount.IsoPath
# Convert hashtable to custom object
$object = New-Object –TypeName PSObject –Prop $info
# Add to array
$vmInfos += $object
}
}
# Dump collected infos
$vmInfos | format-table -autosize
希望对您有所帮助
我尝试将所有安装了 CD 的虚拟机集中到一个 table,但我得到的输出是一行一行的,如:
vm1 \vm1_isopath\ 虚拟机2 \vm2_isopath\
是否可以获取 1 table 中包含 2 列虚拟机名称和 ISOPath 的所有信息?
我的代码是:
$VMs=Get-VM
ForEach ( $vm in $VMs)
{
$VMmount=Get-CDDrive -VM $vm
if ($VMmount.IsoPath)
{
$vm | select Name
$VMmount.IsoPath
}
}
谢谢。
我将您的代码扩展为:
$VMs=Get-VM
$vmInfos = @()
ForEach ( $vm in $VMs)
{
$VMmount=Get-CDDrive -VM $vm
if ($VMmount.IsoPath)
{
# Store needed info in hashtable
$info = @{}
$info.name = ($vm | select -ExpandProperty Name)
$info.IsoPath = $VMmount.IsoPath
# Convert hashtable to custom object
$object = New-Object –TypeName PSObject –Prop $info
# Add to array
$vmInfos += $object
}
}
# Dump collected infos
$vmInfos | format-table -autosize
希望对您有所帮助