I am trying to write a powershell script using -replace or something equivalent to search a specified node, based on conditions, and replace only a portion of the text with other text. Is this even possible?
Here is some example nodes I am trying to edit based on the value of 'Path':
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var1].Properties[Value]"
ValueType="String">
<ConfiguredValue>Some Text Here</ConfiguredValue>
</Configuration>
<Configuration ConfiguredType="Property" Path="\Package.Variables[User::var2].Properties[Value]"
ValueType="String">
<ConfiguredValue>More Text Here</ConfiguredValue>
</Configuration>
Below is my current code setup to replace the entire string but id prefer for it to replace "text" with "content" so the node will now say "Some Content Here". I tried using -replace but I could not get it to work properly.
#defaults
$xml = [xml](Get-Content $file.FullName)
$node = $xml.DTSConfiguration.Configuration
#updating individual attributes
$pathVar = "var1"
$confVal = ""
($xml.DTSConfiguration.Configuration | Where-Object {$_.Path -like ("*{0}*" -f $pathVar)}).ConfiguredValue = ("{0}" -f $confVal)
$xml.Save($file.FullName)