title: PowerShell Script to Delete XML Element
body: <p>I have an XML doccument that looks like this:</p>
  
  <pre><code>&lt;Task&gt;
      &lt;Settings&gt;
      &lt;/Settings&gt;
      &lt;Sub&gt;foo&lt;/Sub&gt;
      &lt;Body&gt;bar&lt;/Body&gt;
  &lt;/Task&gt;
  </code></pre>
  
  <p>From PowerShell I can happily get the contents of 'Sub' and 'Body' using:</p>
  
  <pre><code>$Body = $XMLFile.Task.Body
  </code></pre>
  
  <p>But I am trying to REMOVE the 'Sub' and 'Body' Tags completely so the XML would be:</p>
  
  <pre><code>&lt;Task&gt;
      &lt;Settings&gt;
      &lt;/Settings&gt;
  &lt;/Task&gt;
  </code></pre>
  
  <p>I have already Tried many things, Including:</p>
  
  <ul>
  <li>Using the <code>.RemoveChild()</code> method (Threw an exeption relating to Object reference)</li>
  <li>Removing with an XPath Statement and adding a Pipe to remove in one line</li>
  <li><p>Even opening the file as a text file and trying: </p>
  
  <p><code>Get-Content $_.FullName -notmatch "&lt;Sub&gt;" | out-file $_.FullName</code></p></li>
  </ul>
  
  <p>^^ This does nothing at all</p>
  
  <p>Also for this application of script I would be unable to use any third party modules</p>