Получить XML узлов и подузлов по заказу с помощью PowerShell - PullRequest
0 голосов
/ 02 апреля 2020

Я сталкиваюсь с некоторыми проблемами, чтобы получить узлы и подузлы по порядку. Не могли бы вы ответить?

МОЙ XML:

<?xml version="1.0" encoding="UTF-8"?>
<sequence version="3.10">
  <referenceList>
    <reference package="PSOO01434" />
  </referenceList>
  <group name="STEP-1 - Set TS variables" description="">
    <step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-2 - Build TS variables" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false">
      <action>smsswd.exe /run:PSOO01434 Powershell.exe -executionpolicy Bypass -file .\BuildTSVariable.ps1 --AdvID %_SMSTSAdvertID%</action>
      <defaultVarList>
        <variable name="CommandLine" property="CommandLine" hidden="true">Powershell.exe -executionpolicy Bypass -file .\BuildTSVariable.ps1 --AdvID %_SMSTSAdvertID%</variable>
        <variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection">true</variable>
        <variable name="PackageID" property="PackageID" hidden="true">PSOO01434</variable>
        <variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser">false</variable>
        <variable name="SuccessCodes" property="SuccessCodes" hidden="true">0 3010</variable>
        <variable name="SMSTSRunCommandLineUserPassword" property="UserPassword" />
      </defaultVarList>
    </step>
  </group>
  <group name="STEP-3 - Install" description="">
    <condition>
      <expression type="SMS_TaskSequence_VariableConditionExpression">
        <variable name="Operator">equals</variable>
        <variable name="Value">1</variable>
        <variable name="Variable">_Install</variable>
      </expression>
    </condition>
    <step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-4 -Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false">
      <action>smsswd.exe /run: msg Admin "Install Group executed"</action>
      <defaultVarList>
        <variable name="CommandLine" property="CommandLine" hidden="true">msg Admin "Install Group executed"</variable>
        <variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection">false</variable>
        <variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser">false</variable>
        <variable name="SuccessCodes" property="SuccessCodes" hidden="true">0 3010</variable>
      </defaultVarList>
    </step>
  </group>
  <group name="STEP-5 - Uninstall" description="">
    <condition>
      <expression type="SMS_TaskSequence_VariableConditionExpression">
        <variable name="Operator">equals</variable>
        <variable name="Value">1</variable>
        <variable name="Variable">_Uninstall</variable>
      </expression>
    </condition>
    <step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-6 - Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false">
      <action>smsswd.exe /run: msg Admin "Uninstall Group executed"</action>
      <defaultVarList>
        <variable name="CommandLine" property="CommandLine" hidden="true">msg Admin "Uninstall Group executed"</variable>
        <variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection">false</variable>
        <variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser">false</variable>
        <variable name="SuccessCodes" property="SuccessCodes" hidden="true">0 3010</variable>
      </defaultVarList>
    </step>
    <group name="STEP-7 - Group" description="">
      <step type="SMS_TaskSequence_RunCommandLineAction" name="STEP-8 - Run Command Line" description="" runIn="WinPEandFullOS" successCodeList="0 3010" retryCount="0" runFromNet="false">
        <action>smsswd.exe /run: Cmd.exe</action>
        <defaultVarList>
          <variable name="CommandLine" property="CommandLine" hidden="true">Cmd.exe</variable>
          <variable name="SMSTSDisableWow64Redirection" property="DisableWow64Redirection">false</variable>
          <variable name="_SMSTSRunCommandLineAsUser" property="RunAsUser">false</variable>
          <variable name="SuccessCodes" property="SuccessCodes" hidden="true">0 3010</variable>
        </defaultVarList>
      </step>
    </group>
  </group>
</sequence>

Вопрос: Как получить узлы и подузлы по порядку, как показано ниже?

Я ожидая выход от этого XML, как показано ниже:

OutPut Required

1 Ответ

0 голосов
/ 02 апреля 2020

Вы можете сделать что-то вроде следующего, что должно начать вас:

$x = [xml](Get-Content myxml.xml)
$x.SelectNodes('//group') | Foreach-Object {
    [pscustomobject]@{Order = $_.Name -replace 'STEP-(\d+).*','$1'
                      Name  = $_.Name
                      Node  = 'Group'
    } 
    $_.Step | Foreach-Object {
    [pscustomobject]@{Order = $_.Name -replace 'STEP-(\d+).*','$1'
                      Name  = $_.Name
                      Node  = 'Step'
    }
    }
}
...