Edit host file from Within Powershell
I need to be able to manage my environments using a Powershell script. I
need to change my host file periodically. However, whenever I try to edit
the host from my script, I get the following error: Access to the path
C:\windows\system32\drivers\etc\hosts is denied
Currently my script looks like this:
Function ManageHosts([string] $environment) { cd
C:\windows\system32\drivers\etc if($environment.StartsWith("p")) {
get-content .\hosts.prod | set-content .\hosts -force } else { get-content
.\hosts.dev | set-content .\hosts -force } }
No comments:
Post a Comment