您现在的位置是:网站首页> 编程资料编程资料
Powershell小技巧之编辑Hosts文件_PowerShell_
2023-05-26
335人已围观
简介 Powershell小技巧之编辑Hosts文件_PowerShell_
某段时间你可能需要经常去更改hosts文件,硬编码一些dns。你得先找到这个文件,然后鼠标右键选择记事本,打开它。可是当保存时才发现,保存不了,原来需要管理员权限。此时你可以先把它保存到桌面,然后再拷贝回原来的位置,这样稍显麻烦。
另外改完hosts文件,是为了更新dns,此时通常都会伴随一个flush DNS的操作。既然要自动化,那就一起做了算了。
把下面的脚本添加到你的PowerShell Profile文件中,下次直接在PowerShel控制台中键入Edit-Hosts 或者 eh就可以打开Hosts文件了。
复制代码 代码如下:
Function Edit-Hosts
{
Start-Process notepad -Verb runas -ArgumentList $env:windir\System32\drivers\etc\hosts -Wait
ipconfig /flushdns | Out-Null
}
Set-Alias eh Edit-Hosts
您可能感兴趣的文章:
相关内容
- Powershell小技巧之记录脚本的操作_PowerShell_
- Powershell小技巧之获取MAC地址_PowerShell_
- Windows Powershell Do While 循环_PowerShell_
- Windows Powershell Foreach 循环_PowerShell_
- Windows Powershell ForEach-Object 循环_PowerShell_
- Windows Powershell Switch 语句_PowerShell_
- Windows Powershell IF-ELSEIF-ELSE 语句_PowerShell_
- Windows Powershell Where-Object 条件过滤_PowerShell_
- Windows Powershell条件表达式之条件操作符_PowerShell_
- Windows Powershell创建对象_PowerShell_
