2013-06-11 48 views
2

我有一個對象數組,並試圖操縱它,並得到屬性RptFile不存在的錯誤。我檢查了拼寫和所有內容,對於發生的事情感到困惑。找不到對象存在屬性

代碼給錯誤:

$AllContents | Where-Object {$_.RptFile -eq 'CB-Officer Trial New'} 

AllContents | Get-Member returns: 


TypeName: Selected.System.Management.Automation.PSCustomObject 

Name   MemberType Definition            
----   ---------- ----------            
Equals  Method  bool Equals(System.Object obj)       
GetHashCode Method  int GetHashCode()          
GetType  Method  type GetType()           
ToString  Method  string ToString()          
RptFile  NoteProperty System.String RptFile=ABL - Branch5206 Daily OD Report 
TotalSeconds NoteProperty System.String TotalSeconds=25 

所以物業確實存在。任何想法是怎麼回事?如果我只輸入$ AllContents,我也會得到一個帶有屬性的列表。

回答

0
$rptFile = $AllContents | Select -Expand RptFile | Where { $_ eq 'CB-Officer Trial New' } 
+0

,給出了一個列表,其中當我輸入$ AllContents時得到的結果。我正在嘗試過濾。 – user1612851

+0

使用where子句添加管道: –

+0

無法在此對象上找到屬性'RptFile'。確保它存在。 在線:1 char:37 + $ rptFile = $ AllContents |其中{$ _。 <<<< RptFile -eq'CB-Officer Trial New'} | Select -Expand RptFile + CategoryInfo:InvalidOperation:(。:OperatorToken)[],RuntimeException + FullyQualifiedErrorId:PropertyNotFoundStrict – user1612851

2

您的Set-StrictMode值,你可以測試你的代碼之前刪除嚴格的模式是什麼?

Set-StrictMode -Off 

哪些結果:

Get-Member -InputObject $AllContents 

Get-Member -InputObject $AllContents[0].RptFile 
+1

它不會讓我發佈這一切,但第一個說TypeName:System.Object []。第二個給出TypeName:System.String。兩者都列出了排名,同步根,長度和其他一些屬性。沒有rptfile屬性。 – user1612851

1

先嚐試

$AllContents[0].RptFile = '<value>' 

如果沒有這樣的事情應該有所幫助:

[Your.Interface.Implemented.Explicitly].GetProperty("RptFile").SetValue($AllContents[0], '<value>',$null) 
相關問題