title: Powershell script for deleting an XML node in multiple XML files
body: <p>I would like to have a PowerShell script loop through all .xml files in a directory and delete a matching .xml node.  I also want to save a copy of the original .xml file.</p>
  
  <p>I have this line of code which is able to change one file at a time.  However, I would like to have a script that does this for all .xml files in a folder.</p>
  
  <pre><code>Get-Content \\network\path\file1.xml | Where-Object {$_ -notmatch '&lt;NUGLET key="000000000000025"/&gt;'} | Set-Content \\network\path\file1.new.xml
  </code></pre>
  
  <p>I've been working on this script but I'm at a point where it seems to be looking in my documents directory instead of in the network path.</p>
  
  <pre><code>Get-ChildItem \\network\path\ *.xml | 
  ForEach-Object {
  # Load the file's contents, delete string
  (Get-Content $_) | Where-Object {$_ -notmatch '&lt;NUGLET key="000000000000025"/&gt;'} 
  }
  </code></pre>
  
  <p>So why am I getting the following error? </p>
  
  <pre><code>Get-Content : Cannot find path 'C:\Users\username\Documents\file1.xml' because it does not exist.
  At C:\Users\username\Local\Temp\4a8c4fc2-9af6-4c35-ab40-99d88cf67a86.ps1:5 char:14
  +     (Get-Content &lt;&lt;&lt;&lt;  $_) | Where-Object {$_ -notmatch '&lt;NUGLET key="000000000000025"/&gt;'} 
  + CategoryInfo          : ObjectNotFound: (C:\Users\userna...-file1.xml:String) [Get-Content], ItemNotFoundException
  + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
  </code></pre>
  
  <p>And how can I modify the script to make a copy of the original xml file for backup purposes.</p>
  
  <p>EDIT:</p>
  
  <p>So with Nate's suggestion I am now using the following:</p>
  
  <pre><code>Get-ChildItem \\network\path\ *.xml | 
  ForEach-Object {
  # Load the file's contents, delete string
  (Get-Content $_.fullname) | Where-Object {$_ -notmatch '&lt;NUGLET key="000000000000025"/&gt;' | Set-Content $_.fullname} 
  }
  </code></pre>