2012-07-27 35 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}}