简体   繁体   中英

Powershell Format-Table resulting in empty columns

Running:

get-vm -server hyperv
get-vm -server hyperv | format-table -AutoSize

Result in a 5 column output with data in all 5 columns as expected.

Running:

get-vm -server hyperv | select VMElementName,State,Host | format-table -AutoSize
get-vm -server hyperv | format-table -Property VMElementName,State,Host -AutoSize

Results in a 3 column output with data in only the VMElementName column. Any attempt to reduce the number of columns results in all but the VMElementName column is empty. Changing order has no effect. Selecting any single column makes no difference. Only the VMElementName column contains data.

How do I get the rest of the data to be shown?

Using the Hyper-V module from Server 2008 R2, Get-VM returns objects of the type System.Management.ManagementObject#root\\virtualization\\Msvm_ComputerSystem . In other words, these are WMI based objects, where the WMI class is Msvm_ComputerSystem .

Your issue is that this object does not contain some of the properties you are asking for.

If you do a Get-VM | Get-Member Get-VM | Get-Member , you can see the actual properties available, I think what you want is

Get-VM | FT Elementname, statusdescriptions,pscomputername

Elementname                             statusdescriptions                  PSComputerName
-----------                             ------------------                  --------------
Lync - SE                               {Operating normally}                    COOKHAM8
Lync - QMS                              {Operating normally}                    COOKHAM8
Lync - DC                               {Operating normally}                    COOKHAM8
Lync - SPS2010                          {Operating normally}                    COOKHAM8
DEV1 - win7+Dev tools                   {Operating normally}                    COOKHAM8
S1.Cookham/Net (Srv2012)                {Operating normally}                    COOKHAM8
SQL2012                                 {Operating normally}                    COOKHAM8
W8.Cookham.Net(w8 RTM)                  {Operating normally}                    COOKHAM8
Lync - EXUM                             {Operating normally}                    COOKHAM8
SQL2008                                 {Operating normally}                    COOKHAM8

Empty Format-Table columns usually indicate that the associated property doesn't exist or the value for each item is $null or an empty string. If I look at the output of Get-VM on Windows 8 (where I have one hyper-v VM created), I don't see those properties. You can see what properties are available using Get-Member like so:

Get-VM -server hyperv | Get-Member

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM