我需要选择最大计数和计数才能在PowerShell中进行计算。
这是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>
答案 0 :(得分:1)
试试这个:
[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>
'
然后在Powershell提示符中执行:$xml.Para.License.Counter.MaxCount
。这将为您提供xml中所有max count元素的值。在此之后,您可以为要操作的任何元素指定变量。
或者,如果您的XML是文件,则可以使用$xml
[xml]$xml = Get-Content [path_to_your_file]
变量