2013-06-11 112 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) 
相关问题