2012-07-27 39 views
3

我用这个powershell命令属性:格式表和是数组

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

与一个字符串数组作为属性返回对象(CUSTOMPROPERTIES):

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

如何可以仅返回一个数组中的一个元素是一个属性作为一个对象来显示它作为表的一部分?

我的期望输出应该是这样的:

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

回答

3

在您的格式表,改变customproperties要么:

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

如果它是一个数组。如果是收集用途:

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