I'm only finding stuff on how to change the attribute values of a XML element here on StackOverflow.
But how do we change the value of the element itself using PowerShell?
I currently have:
XML
<Task>
<Settings>
...
</Settings>
<Actions Context="Author">
<Exec>
<Command>blablabla</Command>
<Arguments>CHANGETHISVALUE</Arguments>
</Exec>
</Actions>
</Task>
SCRIPT
$filePathToTask = C:\Task.xml
$xml = New-Object XML
$xml.Load($filePathToTask)
$element = $xml.SelectSingleNode("//Arguments")
$element.InnerText("newtext")
$xml.Save($filePathToTask)
However, I can't seem to use methods on the last variable. What am I doing wrong?
Edit
- Added code
The error that I'm getting is You cannot call a method on a null-valued expression
I think my problem lies at:
$ElementToChange = $xml.SelectSingleNode("//Arguments")
Which stays null, but I have tried methods like .SelectNodes
and playing around with the //Arguments
tag but still no success