Suddenly this code ain't working anymore. I'm trying to google this but I can't seem to find any solution how to fix this.
I can't just do
[xml]($deploymentXml.configuration.services).AppendChild($newService)
or
$deploymentServicesNode = [xml]$deploymentXml.configuration.services
$deploymentServicesNode.AppendChild($newService)
Does anyone know what's going on and why this ain't working anymore?
deployment.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration description="Services deployment server">
<services>
</services>
</configuration>
Method invocation failed because [System.String] does not contain a method named 'AppendChild'. At F:\USB\host.ps1:153 char:9 + $deploymentXml.configuration.services.AppendChild($service ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
The part of host.ps1
#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);
}