标签: cscfg

如何将元素添加到 PowerShell 中的空 XML (CSCFG) 节点

我有一个如下所示的 xml 文件(CSCFG 文件)

XML文件:

 <Role name="Role1">
    <Instances count="2" />
    <ConfigurationSettings>
      <Setting name="Key1" value="123456" />
      <Setting name="Key2" value="1234567890" />
      <Setting name="Key3" value="true" />
    </ConfigurationSettings>
    <Certificates>
    </Certificates>
  </Role>
Run Code Online (Sandbox Code Playgroud)

我需要在证书节点内添加多个证书元素。

要成为 XML:

<Role name="Role1">
    <Instances count="2" />
    <ConfigurationSettings>
      <Setting name="Key1" value="123456" />
      <Setting name="Key2" value="1234567890" />
      <Setting name="Key3" value="true" />
    </ConfigurationSettings>
    <Certificates>
      <Certificate name="certificate1" thumbprint="12345678" />
      <Certificate name="certificate2" thumbprint="01234567" />
      <Certificate name="certificate3" thumbprint="09876543" />
    </Certificates>
  </Role>
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码

$xmlDoc = [System.Xml.XmlDocument](Get-Content $configFile);
$xmlDoc.Role.Certificates.AppendChild($xmlDoc.CreateElement("Certificate"));
$newXmlCertificate.SetAttribute(“name”,$certName);
$newXmlCertificate.SetAttribute(“thumbprint”,$CertThumbprint);
$xmlDoc.save($configFile)
Run Code Online (Sandbox Code Playgroud)

这是在执行此操作时遇到的异常: 方法调用失败,因为 [System.String] 不包含名为“AppendChild”的方法。

请帮帮我。

xml powershell azure cscfg

1
推荐指数
1
解决办法
2806
查看次数

标签 统计

azure ×1

cscfg ×1

powershell ×1

xml ×1