【发布时间】:2014-09-05 23:38:45
【问题描述】:
我对 PowerShell 比较陌生,在创建脚本以使用 PowerShell 修改和保存 XML 文件 (web.config) 时遇到问题。 XML文件的结构如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Password" value="Test1234" />
</appSettings>
</configuration>
我尝试了多种方法来尝试让 powershell 编辑密码值并再次保存,但都没有工作。我最近的存在:
$webConfig = "Z:\TEMP\Web.config"
$doc = new-object System.Xml.XmlDocument
$doc.Load($webConfig)
$doc.get_DocumentElement()."appSettings".WebAdminPassword.value = "$Password"
$doc.Save($webConfig)
变量 $Password 是在脚本前面生成的随机 15 个字符的密码。谁能告诉我哪里出错了?谢谢!
【问题讨论】:
标签: xml powershell