0

I have an attribute "Count" in my xml , and when I am trying to access the values of the attribute it giving the count of the array

$Count = $xml.Para.Lic.Counter.Count

Any suggestions would be really helpful

Piotr Sobiegraj
  • 1,775
  • 16
  • 26
  • Possibly a duplicate of https://stackoverflow.com/questions/12212452/how-to-fetch-an-attribute-value-from-xml-using-powershell – Jay Buckman Jun 16 '17 at 18:56
  • @Jay Buckman:Actually I am trying the same way $Count = $xml.Para.Lic.Counter I select Count , but still its giving the count of array not values – chandaluri Pegasian Jun 16 '17 at 19:02

2 Answers2

1

You can use single quotes around names:

$Count = $xml.Para.Lic.Counter.'Count'

However, if 'Counter' is an array, you need to access an instance to get the attribute value:

    $Count = $xml.Para.Lic.Counter[0].Count
NetMage
  • 26,163
  • 3
  • 34
  • 55
0

Both of these work. Maybe there is something else wrong with your XML?

$xml = Get-Content test.xml      
$xml.catalog.counter.Count
$xml.catalog.counter.'Count'

Loading the following test.xml

<?xml version="1.0"?>
<catalog>
    <counter count="150">
    </counter>
</catalog>
Eric Hodges
  • 361
  • 2
  • 5