I am trying to create a batch file in Windows 7 to help me remove Skype Ads.
Here's what I've come with so far:
@echo off
echo Editing '%WINDIR%\System32\Drivers\Etc\Hosts' file
echo 127.0.0.1 apps.skype.com >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.1 g.msn.com >> %WINDIR%\System32\Drivers\Etc\Hosts
echo Editing '%APPDATA%\Skype' config
powershell -Command "(Get-ChildItem %APPDATA%\Skype -Filter "config.xml" -Recurse) | ForEach-Object { $_ -replace '<AdvertPlaceholder>1</AdvertPlaceholder>', '<AdvertPlaceholder>0</AdvertPlaceholder>' } | Set-Content $_"
ipconfig /flushdns
pause
The powershell command throws me an error:
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 '<AdvertPlaceholder>1</AdvertPlaceholder>
', '<AdvertPlaceholder>0</AdvertPlaceholder>' } | Set-Content <<<< $_
+ CategoryInfo : InvalidData: (:) [Set-Content], ParameterBinding
ValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetContentCommand
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.
EDIT:
Here's what I ended up using:
@echo off
echo Editing '%WINDIR%\System32\Drivers\Etc\Hosts' file
echo 127.0.0.1 apps.skype.com >> %WINDIR%\System32\Drivers\Etc\Hosts
echo 127.0.0.1 g.msn.com >> %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 '<(AdvertPlaceholder)>1</\1>', '<$1>0</$1>' | Set-Content $file.fullname }"
ipconfig /flushdns
echo Done. Please restart Skype for changes to take effect.
pause
Confirmed working at the time of this post.