利用PowerShell修改网络配置(IP、网关、子网掩码、DNS)

序
修改IP、网关、子网掩码、DNS等配置时需要打开网络配置器配置,有些麻烦。尤其是经常需要重复性操作时(例如去学校图书馆蹭网)。用PowerShell脚本自动修改,方便简单而且十分轻量,程序只需占用1KB空间。
新的修改方法(CIM)
Common Information Model (CIM)
Windows Management Instrumentation (WMI)
Get-CimInstance[1]
旧的修改方法(WMI)
Get-WmiObject[2]
附:C#代码
代码仓库
Github: https://github.com/Poker-sang/NetworkAdapter

引用图片


参考资料
[1] Get-CimInstance(https://docs.microsoft.com/zh-cn/powershell/scripting/samples/getting-wmi-objects--get-ciminstance-?view=powershell-7.3)
[2] Get-WmiObject(https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-wmiobject?view=powershell-5.1)