Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to remove string entries from host file without adding new line

$
0
0

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


Viewing all articles
Browse latest Browse all 21975

Trending Articles