I use PowerShell to update the list of XML directories for an application on multiple servers, but this causes a problem with the actual updates. Using the following XML as an example, you want to update file paths with qualnas1 to use something like \ GlobalNAS ... etc. And delete the qualnas2 entry.
<?xml version="1.0" encoding="UTF-8" ?> <directory> <filepath>\\qualnas1\library\content</filepath> <filepath>\\qualnas2\library\content</filepath> <filepath type="sssb">\\qualnas1\SSSB\content</filepath> </directory>
The path to the node file with type = sssb works when I use $ _. InnerText, but cannot find a way to update or delete other nodes. Here is my code:
$DirectoryXMLPath = 'C:\Temp\directory.xml' if (Test-Path $DirectoryXMLPath) { $DirectoryXML = New-Object XML $DirectoryXML.Load($DirectoryXMLPath) $DirectoryXML.PreserveWhitespace = $true
If I go through the code using PowerGUI, each node will be found, and the replace / remove attempt will be performed as I expected, but either get errors (XmlElement conversion string) or no errors, but no updates, either depending of how I complete the task. In any case, to change / delete certain nodes if there are no attributes, as in the SSSB example?
source share