title: Get XML Nodes and SubNodes by an order Using PowerShell
body: <p>I am facing some challenges to get the nodes and sub-nodes by an order. Could you please answer?</p>
  
  <p>MY XML: </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;sequence version="3.10"&gt;
    &lt;referenceList&gt;
      &lt;reference package="PSOO01434" /&gt;
    &lt;/referenceList&gt;
    &lt;group name="STEP-1 - Set TS variables" description=""&gt;
      &lt;step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-2 - Build TS variables" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false"&gt;
        &lt;action&gt;smsswd.exe /run:PSOO01434 Powershell.exe -executionpolicy Bypass -file .\BuildTSVariable.ps1 --AdvID %_SMSTSAdvertID%&lt;/action&gt;
        &lt;defaultVarList&gt;
          &lt;variable name="CommandLine" property="CommandLine" hidden="true"&gt;Powershell.exe -executionpolicy Bypass -file .\BuildTSVariable.ps1 --AdvID %_SMSTSAdvertID%&lt;/variable&gt;
          &lt;variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection"&gt;true&lt;/variable&gt;
          &lt;variable name="PackageID" property="PackageID" hidden="true"&gt;PSOO01434&lt;/variable&gt;
          &lt;variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser"&gt;false&lt;/variable&gt;
          &lt;variable name="SuccessCodes" property="SuccessCodes" hidden="true"&gt;0 3010&lt;/variable&gt;
          &lt;variable name="SMSTSRunCommandLineUserPassword" property="UserPassword" /&gt;
        &lt;/defaultVarList&gt;
      &lt;/step&gt;
    &lt;/group&gt;
    &lt;group name="STEP-3 - Install" description=""&gt;
      &lt;condition&gt;
        &lt;expression type="SMS_TaskSequence_VariableConditionExpression"&gt;
          &lt;variable name="Operator"&gt;equals&lt;/variable&gt;
          &lt;variable name="Value"&gt;1&lt;/variable&gt;
          &lt;variable name="Variable"&gt;_Install&lt;/variable&gt;
        &lt;/expression&gt;
      &lt;/condition&gt;
      &lt;step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-4 -Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false"&gt;
        &lt;action&gt;smsswd.exe /run: msg Admin "Install Group executed"&lt;/action&gt;
        &lt;defaultVarList&gt;
          &lt;variable name="CommandLine" property="CommandLine" hidden="true"&gt;msg Admin "Install Group executed"&lt;/variable&gt;
          &lt;variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection"&gt;false&lt;/variable&gt;
          &lt;variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser"&gt;false&lt;/variable&gt;
          &lt;variable name="SuccessCodes" property="SuccessCodes" hidden="true"&gt;0 3010&lt;/variable&gt;
        &lt;/defaultVarList&gt;
      &lt;/step&gt;
    &lt;/group&gt;
    &lt;group name="STEP-5 - Uninstall" description=""&gt;
      &lt;condition&gt;
        &lt;expression type="SMS_TaskSequence_VariableConditionExpression"&gt;
          &lt;variable name="Operator"&gt;equals&lt;/variable&gt;
          &lt;variable name="Value"&gt;1&lt;/variable&gt;
          &lt;variable name="Variable"&gt;_Uninstall&lt;/variable&gt;
        &lt;/expression&gt;
      &lt;/condition&gt;
      &lt;step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-6 - Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false"&gt;
        &lt;action&gt;smsswd.exe /run: msg Admin "Uninstall Group executed"&lt;/action&gt;
        &lt;defaultVarList&gt;
          &lt;variable name="CommandLine" property="CommandLine" hidden="true"&gt;msg Admin "Uninstall Group executed"&lt;/variable&gt;
          &lt;variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection"&gt;false&lt;/variable&gt;
          &lt;variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser"&gt;false&lt;/variable&gt;
          &lt;variable name="SuccessCodes" property="SuccessCodes" hidden="true"&gt;0 3010&lt;/variable&gt;
        &lt;/defaultVarList&gt;
      &lt;/step&gt;
      &lt;group name="STEP-7 - Group" description=""&gt;
        &lt;step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-8 - Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false"&gt;
          &lt;action&gt;smsswd.exe /run: Cmd.exe&lt;/action&gt;
          &lt;defaultVarList&gt;
            &lt;variable name="CommandLine" property="CommandLine" hidden="true"&gt;Cmd.exe&lt;/variable&gt;
            &lt;variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection"&gt;false&lt;/variable&gt;
            &lt;variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser"&gt;false&lt;/variable&gt;
            &lt;variable name="SuccessCodes" property="SuccessCodes" hidden="true"&gt;0 3010&lt;/variable&gt;
          &lt;/defaultVarList&gt;
        &lt;/step&gt;
      &lt;/group&gt;
    &lt;/group&gt;
  &lt;/sequence&gt;
  </code></pre>
  
  <p>Question: How to get Nodes and Sub-nodes by an order as shown below?</p>
  
  <p>I am expecting the output from this XML like below:</p>
  
  <p><a href="https://i.stack.imgur.com/KZsE0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KZsE0.png" alt="OutPut Required"></a></p>