Help with Select-Xml

I’m having problems getting Select-Xml to work. The xml file is converted from a .INI file. I want to extract the information for a repeated Section /Objs/Obj/MS/Obj where the Attribute is “PortForwarding”. Under /Objs/Obj/MS/Obj, there is /Objs/Obj/MS/Obj/MS/S where there are multiple rows for <S> … </S> each with an array of values I want to gather into a data table.

[xml file]

So… In Powershell, I can get a datatable to use …



Column1 Column2 Column3 Column4 Column5 Column6 Column7 Column8
“0000.ACQ-DEV-ABC1”>Local, fred.smith@,;11111, -1, C:\Keys\PrivateKey.ppk,, No proxy selected, 0
“0001.ACQ-QA-ABC1”>Local, fred.smith@,;11112, -1, C:\Keys\PrivateKey.ppk,, No proxy selected, 0

Thanks in advance!





The part that you are probably missing would be the XML namespace try the code fragment below:

$ns = @{"NS"=""}
$o = Select-Xml  -Path .\forumq.xml -Namespace $ns -XPath "//NS:Obj[@N='PortForwarding']/NS:MS/NS:S"

That should give you the results below

Local;fred.smith@;;11111;-1;C:\Keys\PrivateKey.ppk;;No proxy selected;0
Local;fred.smith@;;11112;-1;C:\Keys\PrivateKey.ppk;;No proxy selected;0

You could also make life easier on yourself by just using import-clixml cmdlet to get the same result.

$o= Import-Clixml .\forumq.xml