title: Search for a xml file and replace a string inside it
body: <p>I am trying to create a batch file in Windows 7 to help me remove Skype Ads.</p>
  
  <p>Here's what I've come with so far:</p>
  
  <pre><code>@echo off
  
  echo Editing '%WINDIR%\System32\Drivers\Etc\Hosts' file
  echo 127.0.0.1       apps.skype.com &gt;&gt; %WINDIR%\System32\Drivers\Etc\Hosts
  echo 127.0.0.1       g.msn.com &gt;&gt; %WINDIR%\System32\Drivers\Etc\Hosts
  
  echo Editing '%APPDATA%\Skype' config
  powershell -Command "(Get-ChildItem %APPDATA%\Skype -Filter "config.xml" -Recurse) | ForEach-Object { $_ -replace '&lt;AdvertPlaceholder&gt;1&lt;/AdvertPlaceholder&gt;', '&lt;AdvertPlaceholder&gt;0&lt;/AdvertPlaceholder&gt;' } | Set-Content $_"
  
  ipconfig /flushdns
  
  pause
  </code></pre>
  
  <p>The powershell command throws me an error:</p>
  
  <pre><code>Editing 'C:\Users\user\AppData\Roaming\Skype' config
  Set-Content : Cannot bind argument to parameter 'Path' because it is null.
  At line:1 char:218
  + (Get-ChildItem C:\Users\user\AppData\Roaming\Skype -Filter config.xml -Recurse) | ForEach-Object { $_ -replace '&lt;AdvertPlaceholder&gt;1&lt;/AdvertPlaceholder&gt;
  ', '&lt;AdvertPlaceholder&gt;0&lt;/AdvertPlaceholder&gt;' } | Set-Content &lt;&lt;&lt;&lt;  $_
      + CategoryInfo          : InvalidData: (:) [Set-Content], ParameterBinding
     ValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand
  </code></pre>
  
  <p>What am I doing wrong? How do I Set-Content to a file found by Get-ChildItem? If you have another approach, I'd like to hear it too. Much appreciated.</p>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>Here's what I ended up using:</p>
  
  <pre><code>@echo off
  
  echo Editing '%WINDIR%\System32\Drivers\Etc\Hosts' file
  echo 127.0.0.1       apps.skype.com &gt;&gt; %WINDIR%\System32\Drivers\Etc\Hosts
  echo 127.0.0.1       g.msn.com &gt;&gt; %WINDIR%\System32\Drivers\Etc\Hosts
  
  echo Editing '%APPDATA%\Skype' config
  powershell -noprofile -c "$files = Get-ChildItem $env:AppData\Skype -Recurse config.xml; foreach($file in $files) { (Get-Content $file.fullname) -replace '&lt;(AdvertPlaceholder)&gt;1&lt;/\1&gt;', '&lt;$1&gt;0&lt;/$1&gt;' | Set-Content $file.fullname }"
  
  ipconfig /flushdns
  
  echo Done. Please restart Skype for changes to take effect.
  
  pause 
  </code></pre>
  
  <p>Confirmed working at the time of this post.</p>