zoukankan      html  css  js  c++  java
  • 分享powershell设定网卡,ip,网关,dns的命令

    -------------------------------------------------【系统需求】-------------------------------------------------

    不支持win7,win2008r2

    支持win8及以上

    支持win2012及以上。

    -------------------------------------------------【获取网卡】-------------------------------------------------

    获取所有网卡:
    Get-NetAdapter
     
     
    获取单个网卡:
    Get-NetAdapter -Name "Ethernet0" #或以太网,
    或:
    Get-NetAdapter -InterfaceIndex 8
    ================================================================================================================
    获取网卡物理信息
    Get-NetAdapterHardwareInfo

    -------------------------------------------------【获取ip,网关等】-------------------------------------------------

    Get-NetIPConfiguration -InterfaceAlias Ethernet0 -Detailed#或以太网,
     
     
    #获取ip
    (Get-NetAdapter -Name ethernet0 | Get-NetIPAddress).IPv4Address

    -------------------------------------------------【重启网卡】-------------------------------------------------

    Restart-NetAdapter -InterfaceAlias Ethernet0 #或以太网
     

    -------------------------------------------------【设定ip,网关】-------------------------------------------------

    在远程win2019上,更改ip。更改成功后会卡死,需要重新用新ip连接win2019。
    (Get-NetAdapter)[-1] | New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.11.220 -PrefixLength 8 -DefaultGateway 192.168.11.1
     
     
    #更改ip
    (Get-NetAdapter)[-1] | Set-NetIPAddress  -IPAddress 192.168.11.90

    #设定成从dhcp获取
    (Get-NetAdapter)[-1] | Set-NetIPInterface -Dhcp Enabled
    ================================================================================================================
    禁用ipv6
    (Get-NetAdapter)[-1]| Disable-NetAdapterBinding -ComponentID ms_tcpip6

    -------------------------------------------------【设定dns】-------------------------------------------------

    (Get-NetAdapter)[-1] | Set-DNSClientServerAddress -ServerAddresses 192.168.11.1,114.114.114.114
     
     
    #自动获取dns
    (Get-NetAdapter)[-1] |Set-DnsClientServerAddress -ResetServerAddresses

    -------------------------------------------------【机子改名】-------------------------------------------------

    Rename-Computer -ComputerName . -NewName 'ps传教士2020' #这条命令不支持中文机子名,垃圾。
    (Get-WmiObject win32_computersystem).rename('ps传教士2021') #good

    -------------------------------------------------【设定路由】-------------------------------------------------

    添加:
    New-NetRoute -DestinationPrefix "0.0.0.0/0" -NextHop "192.168.12.2" -InterfaceIndex 8
     
    删除:
    Set-NetIPInterface -InterfaceAlias Ethernet0| Remove-NetRoute -Confirm:$false
  • 相关阅读:
    一步一步实现自己的模拟控件(4)——根控件
    一步一步实现自己的模拟控件(6)——控件树及控件区域
    ATL COM初探(1)
    一步一步实现自己的模拟控件(2)——窗口过程thunk
    一步一步实现自己的模拟控件(3)——Widget驱动
    关于硬盘的一些知识
    Win32中TreeView控件的使用方法,类似于资源管理器中文件树形显示方式
    笔记本双系统XP与Ubuntu,重装XP后如何恢复grup引导,另附操作系统启动过程
    vim常用命令
    MFC中CListCtrl控件的使用方法
  • 原文地址:https://www.cnblogs.com/piapia/p/13446456.html
Copyright © 2011-2022 走看看