I want to delete a line from host file upon matching the string and i am using below code..however it keeps adding new line and because of that new contents appear in middle of the host file.Kindly suggest what is wrong in below code.
(Get-Content "C:\Temp\host.txt") |
Foreach-Object {$_ -replace "google.com", ""} |
Set-Content "C:\Temp\host.txt"
(Get-Content "C:\Temp\host.txt") |
Foreach-Object {$_ -replace "yahoo.com", ""} |
Set-Content "C:\Temp\host.txt"
Umeed4u