title: Updating a string from XML using PowerShell
body: <p>I'm retrieving a string of text from some XML data, and then trying to replace that string with something else. The code I'm using is:</p>
  
  <pre><code>$newstring = "mystring"
  $bar = Get-Gpo -Name "My GPO"
  $gpoid = $bar.Id.ToString()
  $drivesxml = New-Object XML
  $drivesxml.Load("\\mydomain.co.uk\sysvol\mydomain.co.uk\Policies\{gpoid}\User\Preferences\Drives\drives.xml")
  $oldpath = $drivesxml.Drives.Drive.Properties.Path[0]
  $oldlabel = $drivesxml.Drives.Drive.Properties.Label[0]
  #1
  [string]$newtemppath = $oldpath -replace "Oldstring$", "$newstring"
  [string]$newtemplabel = $oldlabel -replace "^Oldstring", "$newstring"
  #2
  $drivesxml.Drives.Drive.Properties.Path[0] = $newtemppath
  $drivesxml.Drives.Drive.Properties.Label[0] = $newtemplabel
  #3
  $drivesxml.Save("\\mydomain.co.uk\sysvol\mydomain.co.uk\Policies\{gpoid}\User\Preferences\Drives\drives.xml")
  </code></pre>
  
  <p>It retrieves the XML from sysvol fine, and at point #1 if I query <code>$oldpath</code> and <code>$oldlabel</code> they contain the expected text from the XML. </p>
  
  <p>At #2 if I query <code>$newtemppath</code> and <code>$newtemplabel</code> the strings are returned as expected with the text amended so instances of "Oldstring" have been replaced by "mystring".</p>
  
  <p>At #3 if I query <code>$drivesxml.Drives.Drive.Properties.Path[0]</code> and <code>$drivesxml.Drives.Drive.Properties.Label[0]</code> I'd expect them to return the same content as the <code>$newtemppath</code> and <code>$newtemplabel</code> variables, but instead they continue to return their original values. </p>
  
  <p>After saving the XML if I query it again the content hasn't changed.</p>
  
  <p>Can anyone see what I might be doing wrong with the assignment between #2 and #3?</p>