If (select-string -path "c:\Windows\System32\drivers\etc\hosts" -pattern "String to look for") ` {(Get-Content c:\Windows\System32\drivers\etc\hosts).replace('String to look for', 'String to replace with') | Set-Content c:\Windows\System32\drivers\etc\hosts} Else{"Nothing happened"}