Help with Select-Xml

Welcome Forums General PowerShell Q&A Help with Select-Xml

Viewing 1 reply thread
  • Author
    • #184874
      Topics: 3
      Replies: 2
      Points: 39
      Rank: Member

      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!





    • #185066
      Topics: 1
      Replies: 20
      Points: 77
      Helping Hand
      Rank: Member

      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
Viewing 1 reply thread
  • The topic ‘Help with Select-Xml’ is closed to new replies.