我面临着按顺序获取节点和子节点的一些挑战。你能回答一下吗?
我的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的输出如下所示:

发布于 2020-04-03 01:13:30
您可以执行类似于以下操作的操作,这将使您开始:
$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'
}
}
}https://stackoverflow.com/questions/60994432
复制相似问题