longneck
longneck

Reputation: 12226

format-table and properties that are arrays

i use this powershell command:

get-vm | ft name, *start*, *stop*, customproperties

that returns objects with a string array as a property (customproperties):

Name                StartAction DelayStart      StopAction CustomProperties
----                ----------- ----------      ---------- ----------------
TKAD4        AlwaysAutoTurnOnVM          0 ShutdownGuestOS {NoStartupDelay, ...
TKAD3        AlwaysAutoTurnOnVM          0 ShutdownGuestOS {NoStartupDelay, ...

how can i return just one element from an array the is a property as an object to display it as part of a table?

my desired output would look like this:

Name                StartAction DelayStart      StopAction        Custom1
----                ----------- ----------      ----------        -------
TKAD4        AlwaysAutoTurnOnVM          0 ShutdownGuestOS NoStartupDelay
TKAD3        AlwaysAutoTurnOnVM          0 ShutdownGuestOS NoStartupDelay

Upvotes: 6

Views: 7025

Answers (1)

Keith Hill
Keith Hill

Reputation: 201632

In your Format-Table, change customproperties to either:

@{label='Custom1';e={$_.CustomProperties[0]}}

If it is an array. If it is a collection use:

@{label='Custom1';e={$_.CustomProperties | Select -First 1}}

Upvotes: 7

Related Questions