我有以下 XML:
<?xml version="1.0" encoding="utf-8"?>
<Topology>
<MyProjectserver1 desc="name of the server"></MyProjectserver1>
</Topology>
我尝试了以下操作,但没有得到更新
$path = 'C:\newfolder\data.xml'
$MyProjectserver1 ='XYZAB'
$xml =[xml](Get-Content -Path $path)
$node =$xml.Topology.MyProjectserver1 |
Where {$_.desc -eq 'name of the server'}
$node =$MyProjectserver1
$xml.Save($path)
一旦执行上述 PowerShell 脚本,它就不会更新 XML 内容。
理想情况下,PowerShell 脚本应该按如下方式更新 XML 内容中的服务器名称:
<?xml version="1.0" encoding="utf-8"?>
<Topology>
<MyProjectserver1 desc="name of the server">XYZAB</MyProjectserver1>
</Topology>