簡體   English   中英

PowerCLI-在1個表中獲取VM CD-mount

[英]PowerCLI- get VM cd-mount in 1 table

我嘗試獲取所有在一張表中具有已裝入cd的vm,但是我得到的輸出是一行一行,例如:

vm1 \\ vm1_isopath \\ vm2 \\ vm2_isopath \\

是否可以在1表中包含2列(VM名稱和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 

希望能有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM