从 powershell 编辑 XML 文件

从 powershell 编辑 XML 文件

我有下面这个 XML 文件,需要编辑。

<?xml version="1.0"?>
<rdwastr:strings xmlns:rdwastr="urn:microsoft.com:rdwastrings">
  <string id="PageTitle">RD Web Access</string>
  <string id="NoScriptWarning">
    <p id="NoScript1">RD Web Access requires JScript. This Web browser either does not support JScript, or scripts are being blocked.</p>
    <br/>
    <br/>
    <p id="NoScript2">To find out whether your browser supports JScript, or to allow scripts, see the browser's online Help.</p>
  </string>
  <string id="HeadingRDWA">RD Web Access</string>
  <string id="HeadingApplicationName">RemoteApp and Desktop Connection</string>
  .
  .
  .
  <string id="PrivateComputer">I am using a private computer that complies with my organization's security policy.</string>
  <string id="MoreInformation">More information...</string>
  <string id="PrivateMore">By selecting this option you can save your credentials so that they can be used in the future when connecting to these programs. Before you select this option, please ensure that saving your credentials is in compliance with your organization's security policy.</string>
  <string id="HideMore">Hide additional information...</string>
</rdwastr:strings>

网上有几个例子,但我还没有得到结果,这是我最后尝试的。显然分号可能是一个问题。

$xml = [xml](Get-Content \\$client.xyz.com\C$\Windows\Web\RDWeb\Pages\en-US\RDWAStrings.xml)
$node = $xml."rdwastr:strings".string | where {$_.id -eq 'HeadingApplicationName'}
Write-Host $node
$node.Value = "whatever"

Write-Host 没有返回任何内容,因此我假设前一个语句没有返回任何内容并将其分配给节点。我该如何解决这个问题?

答案1

我使用 XML 的经验至少可以说有限,但是类似这样的内容怎么样:

$node = $xml.strings.string | where { $_.id -eq "HeadingApplicationName" }
Write-Host $node.'#text'
$node.'#text' = "whatever"

在我有限的测试中似乎有效......

相关内容