我将XML文件内容分配给一个变量$config,然后使用另一个变量$market来存储XPath查询的输出:
$config = Get-Content -Path "C:\files\configs\config.xml" -raw
$market = (select-xml -Content $config -xpath /process-config/input/filePattern/marketCode).node.'#text'然后添加以下行:
write-host this is $market输出是这样的:
PS C:\ps_scripts> .\xmltest.ps1
this is citigroup_ams
#text
-----
citigroup_ams我想要的输出是:
PS C:\ps_scripts> .\xmltest.ps1
this is citigroup_ams 我试图在第二行的末尾添加| Out-Null,但在这种情况下,只有Write-Host cmdlet的输出被抑制。是否有其他方法可以抑制Select-Xml的输出
发布于 2020-05-05 10:30:08
你可能正在寻找类似这样的东西:
$config = [xml]@'
<process-config>
<input>
<filePattern>
<marketCode>citigroup_ams</marketCode>
</filePattern>
</input>
</process-config>
'@
$market = $config.SelectNodes("/process-config/input/filePattern/marketCode/text()").Value
Write-Host "this is" $market输出:this is citigroup_ams
https://stackoverflow.com/questions/61601804
复制相似问题