2011-07-18 20 views
0

我收到以下错误,我不明白为什么或它要求什么。Powershell:Format-Table:非法密钥计数

我想在一个表中显示的对象是:

function newURLObject() 
{ 
# param ([String]$Value, [Int]$Count = "1", [String]$IP) 
    param ([String]$Value, [Int]$Count = "1") 


    $obj = new-object PSObject 
    $obj | add-member -type NoteProperty -Name Value -Value $Value.substring(1) 
    $obj | add-member -type NoteProperty -Name Count -Value $Count 
# $obj | add-member -type NoteProperty -Name IP -Value $IP 

    return $obj 
} 

的基本流程如下。

#< Declare Objects> 
#< Code to create an array of those objects > 

$z = @{Expression={$_.Count};Label="Count";width=5}, @{Expression={$_.Value};Label="URL";count=35} 

$y = $listOfRequestedURLs | sort count -descending | select -first 30 | ft $z 


Format-Table : Illegal key count 
At C:\Temp\parse IIS logs.ps1:231 char:8 
+ $y | ft <<<< $z 
    + CategoryInfo   : InvalidArgument: (:) [Format-Table], NotSupportedException 
    + FullyQualifiedErrorId : DictionaryKeyIllegal,Microsoft.PowerShell.Commands.FormatTableCommand 

我知道这些值在数组中;但它不会正确显示。如果我在没有格式表的情况下显示它,值字段只显示为空。

回答

5

你有一个非法格式键值名,将其删除(或重命名为宽度):

@ {表达= {$ _值};标签= “URL”。 count = 35}

+0

Err ..对不起,因为密集,但我不明白你与粗体的区别。 – Robert

+0

有效的键名是:Expression,FormatString,Label/Name,Width和Alignment。显然伯爵不是其中之一。 –

+0

深度也是一个有效的密钥名称。 –