Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Querying Inner Text with Multiple Attributes

$
0
0

Ah, are you using PowerShell 2.0, by chance? PowerShell 3.0 added a feature called “Member Enumeration”, which would come into play on this line:

$DRSegment1 = ($node.SelectNodes("//DATASTREAM.ACDSEGMENT") | Where-Object {$_.accounted -eq "DR" -and $_.index -eq "1"}).InnerXML

If the expression in parentheses evaluates to an array, then the “.InnerXML” part of the expression tries to read an “InnerXML” property from System.Array (in PowerShell 2.0), which doesn’t exist. In PowerShell 3.0 or later, after seeing that there’s no InnerXML property and that the expression on the left of the . is a collection, it tries evaluating the InnerXML property for you on every element of the collection.

Here’s how you could make that line work in 2.0 (with some line breaks added for clarity):

$DRSegment1 = $node.SelectNodes("//DATASTREAM.ACDSEGMENT") |
              Where-Object {$_.accounted -eq "DR" -and $_.index -eq "1"} |
              Select-Object -ExpandProperty InnerXML


Viewing all articles
Browse latest Browse all 13067

Trending Articles