简体   繁体   English

我如何解析Powershell中的XML以从最后一个模块中选择项目

[英]How do i parse the XML in powershell to select the items from the last module

I need to select the max count and count to do a calculation in PowerShell. 我需要选择最大计数并在PowerShell中进行计算。

Here is the xml example: 这是xml示例:

<Para TimeStamp="1497627698"
       Signature="6D09881827E0973">
    <License Module="page"
           ServerId="1452"
           EnterBy="20110630"
           RenewDate="20170701"
           RenewPeriod="Year"
           MaxNumWorkflowServers="1"
           MaxVersion="3.0"
           MaxNumExportFields="10"
           TableRecognition="FALSE"
           DisabledOn="20170613">
        <Counter Name="Pages"
             MaxCount="7500"
             Count="7500"/>
    </License>
    <License Module="page"
           ServerId="1452"
           EnterBy="20170613"
           RenewDate="20170701"
           RenewPeriod="Year"
           MaxNumWorkflowServers="1"
           MaxVersion="3.0"
           MaxNumExportFields="10"
           TableRecognition="FALSE"
           ValidUntil="20170620">
        <Counter Name="Pages"
             MaxCount="8000"
             Count="7613"/>
    </License>
</Para>

Try This: 尝试这个:

    [xml]$xml = '
<Para TimeStamp="1497627698"
       Signature="6D09881827E0973">
    <License Module="page"
           ServerId="1452"
           EnterBy="20110630"
           RenewDate="20170701"
           RenewPeriod="Year"
           MaxNumWorkflowServers="1"
           MaxVersion="3.0"
           MaxNumExportFields="10"
           TableRecognition="FALSE"
           DisabledOn="20170613">
        <Counter Name="Pages"
             MaxCount="7500"
             Count="7500"/>
    </License>
    <License Module="page"
           ServerId="1452"
           EnterBy="20170613"
           RenewDate="20170701"
           RenewPeriod="Year"
           MaxNumWorkflowServers="1"
           MaxVersion="3.0"
           MaxNumExportFields="10"
           TableRecognition="FALSE"
           ValidUntil="20170620">
        <Counter Name="Pages"
             MaxCount="8000"
             Count="7613"/>
    </License>
</Para>
'

Then execute: $xml.Para.License.Counter.MaxCount in your Powershell prompt. 然后在Powershell提示符中执行: $xml.Para.License.Counter.MaxCount That will give you the values for all the max count elements in your xml. 这将为您提供xml中所有最大数量元素的值。 You can specify variables for whatever elements you want to operate against after that. 之后,您可以为要操作的任何元素指定变量。

Optionally, if your XML is a file, you can import the file into the $xml variable using [xml]$xml = Get-Content [path_to_your_file] (可选)如果XML是文件,则可以使用[xml]$xml = Get-Content [path_to_your_file]将文件导入$xml变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM