2010-05-03 33 views
7

在PowerShell中使用一個簡單的幫助函數,該函數接受幾個參數並創建一個自定義Enumerable對象並將該對象輸出到管道。我遇到的問題是PowerShell總是輸出一個System.Array,其中包含由我的自定義Enumerable對象枚舉的對象。我如何讓PowerShell解開Enumerable對象的包裝?如何阻止PowerShell解包Enumerable對象?

的代碼:http://gist.github.com/387768

+3

PowerShell有時太聰明瞭。看看http://stackoverflow.com/questions/1918190/strange-behavior-in-powershell-function-returning-dataset-datatable – stej 2010-05-03 09:38:18

回答

7

嘗試從

$row 

, $row 

EDIT改變線46:如約翰正確地指出的那樣,一元運算符逗號創建與陣列一名成員。

+3

說明:這包裝任何你想返回一個數組(只有一個元素)。這個數組將被解包,但其內容不是。 – Joey 2010-05-03 09:13:56