title: Is there a built-in property or method in PowerShell/.NET to check if the XML one is working with has been modified?
body: <p>I've written a PowerShell script to make modifications to XML files, but since not every XML file needs to be updated I don't want to needlessly write to the file.  I'm currently setting a variable to <code>$true</code> when I've (or the script) made a modification:</p>
  
  <pre><code>[bool]$Modified = $false
  [string]$PathToXML = $env:UserProfile + '\test.xml'
  $XMLObject = New-Object XML
  $XMLObject.Load($PathToXML)
  If($XMLObject.property.otherproperty -ne 'Goldfish')
      {
          $XMLObject.property.otherproperty = 'Goldfish'
         [bool]$Modified = $true
      }
  if($Modofied -eq $true) { $XMLObject.Save($PathToXML) }
  </code></pre>
  
  <p>But this got me wondering: Is there is a built-in property or method in PowerShell or .NET that would automatically track modifications to the already loaded XML object and return a boolean value which would indicate whether or not the already loaded XML object was modified?  Something like:</p>
  
  <pre><code>[string]$PathToXML = $env:UserProfile + '\test.xml'
  $XMLObject = New-Object XML
  $XMLObject.Load($PathToXML)
  # Checking $XMLObject.IsChanged would return false
  If($XMLObject.property.otherproperty -ne 'Goldfish')
      {
          $XMLObject.property.otherproperty = 'Goldfish'
          # A this point $XMLObject.IsChanged is now true
      }
  if($XMLObject.IsChanged) { $XMLObject.Save($PathToXML) }
  </code></pre>
  
  <p>The closest example I can provide is the IsChanged property in the Microsoft.ConfigurationManagement.ApplicationManagement.Application class: Once you've deserialized the XML and make a change to any property, the <code>IsChanged</code> property is automatically updated from false to true.</p>