Question:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
title text 1 |
I am a Powershell newbie and find a question on xml and format-table. Given above xml file. If I run below script to display tickets in a table, the value of “number”, “closed” could not be shown
1 2 3 |
$t = [xml](new-object system.net.webclient).downloadstring($xmlfilepath) $t.tickets.ticket | Format-Table -Property title, state, user-name, url, number, closed |
Return:
1 2 3 4 5 |
title state user-name number closed ----- ----- --------- ------ ------ title text 1 resolved Username number closed title text 2 resolved Username number closed |
Is it the only way I have to use
foreach
and selectSingleNode("ticket").get_InnerXml()
to get all the values?
Thank you.
Answer:
If you notice those nodes have attributes so you will need to get to the data of the node. try the following:
1 2 3 4 |
$t.tickets.ticket | Format-Table -AutoSize -Property title, state, user-name, url, @{Label="number"; Expression={$_.number."#text"}}, @{Label="closed"; Expression={$_.closed."#text"}} |