Xml 方法调用失败,因为[System.String]不包含名为';追加儿童';
突然间,这个代码不再工作了。我试图用谷歌搜索这个问题,但我似乎找不到任何解决办法来解决这个问题 我不能这么做Xml 方法调用失败,因为[System.String]不包含名为';追加儿童';,xml,powershell,Xml,Powershell,突然间,这个代码不再工作了。我试图用谷歌搜索这个问题,但我似乎找不到任何解决办法来解决这个问题 我不能这么做 [xml]($deploymentXml.configuration.services).AppendChild($newService) 或 有人知道这是怎么回事吗?为什么这不管用了 deployment.xml <?xml version="1.0" encoding="utf-8"?> <configuration description="Services
[xml]($deploymentXml.configuration.services).AppendChild($newService)
或
有人知道这是怎么回事吗?为什么这不管用了
deployment.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration description="Services deployment server">
<services>
</services>
</configuration>
在获取XML内容之前,请尝试添加以下内容:
$deploymentFile = $PSScriptRoot + "\USB\Configuration\Deployment.xml";
[System.Xml.XmlDocument]$deploymentXml = New-Object System.Xml.XmlDocument
$deploymentXml = [xml](Get-Content $deploymentFile);
在某些环境中,我遇到了一些类型未设置的问题,例如-SQL作业PowerShell步骤。这就解决了它!你有这方面的文件吗?我不知道我应该把它看作一个数组。
#Location of the file
$deploymentFile = $PSScriptRoot + "\USB\Configuration\Deployment.xml";
$deploymentXml = [xml](Get-Content $deploymentFile);
# check if we got a file, if not do nothing.
if ($deploymentXml) {
Write-Verbose "deployment xml: $deploymentFile"
foreach($service in $Services) {
# Create the new service
$newService = $deploymentXml.CreateElement("service");
$deploymentXml.configuration.services.AppendChild($newService)
Write-Verbose "Adding service: $service"
$newService.SetAttribute("name", $service);
}
$deploymentXml.Save($deploymentFile);
}
$deploymentFile = $PSScriptRoot + "\USB\Configuration\Deployment.xml";
[System.Xml.XmlDocument]$deploymentXml = New-Object System.Xml.XmlDocument
$deploymentXml = [xml](Get-Content $deploymentFile);