In this text we’ll present you find out how to configure community adapter parameters in Windows through PowerShell. We will learn to get and set a static IP handle and DNS (nameservers), configure your community interface to acquire the IP configuration from a DHCP server. You can use these cmdlets to configure community in Core/Nano variations of Windows Server, in , to vary IP settings on distant computer systems/servers and in your PS scripts.
netsh interface ipv4 command was used to configure Windows community settings from the CLI. In PowerShell three.zero and newer, you should utilize the built-in PowerShell NetTCPIP module to handle Windows community settings.
To get the record of cmdlets on this module, run the next command:
get-command -module NetTCPIP
Managing Network Adapters with PowerShell
Display the record of obtainable community interfaces on a pc:
The cmdlet returns the interface title, its state (Up/Down), MAC handle and port pace.
In this instance, I’ve a number of community adapters on my laptop (apart from the bodily connection, Ethernetzero, I’ve some Hyper-V and VMWare Player community interfaces).
You can refer community interfaces by their names or indexes (the Index column). In our instance, to pick out the bodily LAN adapter Intel 82574L, use the command:
Get-WebAdapter -Name "Ethernetzero"
Get-WebAdapter -InterfaceIndex eight
You can change the adapter title:
Rename-WebAdapter -Name Ethernetzero -NewName LAN
To disable a community interface, use this command:
Get-WebAdapter -InterfaceIndex 13| Disable-WebAdapter
When you allow an interface, you can’t use its index since it isn’t assigned but. You can specify an adapter title or description:
Enable-WebAdapter -InterfaceDescription “Hyper-V Virtual Ethernet Adapter"
If a VLAN is specified for an adapter, you possibly can show it as follows:
Get-WebAdapter | ft Name, Status, Linkspeed, VlanID
Here is how one can get the details about the community adapter driver used:
Get-WebAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName
The details about bodily community adapters (PCI slot, bus, and many others.):
How to View TCP/IP Network Adapter Settings with PowerShell?
To get present community adapter settings (IP handle, DNS, default gateway):
Get-NetIPConfiguration -InterfaceAlias Ethernetzero
To show an in depth details about present community adapter TCP/IP configuration, use this command:
Get-NetIPConfiguration -InterfaceAlias Ethernetzero -Detailed
In this case, the (NetProfile.NetworkClass) of the interface, MTU settings (NetIPv4Interface.NlMTU), whether or not acquiring an IP handle from DHCP is enabled (NetIPv4Interface.DHCP) and different helpful data are displayed.
To get the interface IPv4 handle solely:
(Get-WebAdapter -Name ethernet0 | Get-NetIPAddress).IPv4Address
Using PowerShell to Set Static IP Address
Let’s attempt to set a static IP handle for the NIC. To change an IP handle, a subnet masks and default gateway for a community interface use:
New-NetIPAddress –IPAddress 192.168.2.50 -DefaultGateway 192.168.2.1 -PrefixLength 24 -InterfaceIndex eight
You can set an IP handle utilizing an array construction (extra visually):
$ipParams = @
If the static IP handle has already been configured and also you need to change it, the Set-NetIPAddress cmdlet is used:
Set-NetIPAddress -InterfaceIndex eight -IPAddress 192.168.2.90
To disable acquiring an IP handle from DHCP in your adapter, run the command:
Set-NetIPInterface -InterfaceAlias Ethernetzero -Dhcp Disabled
To view the routing desk, the Get-NetRoute cmdlet is used. To add a brand new route, use the New-NetRoute cmdlet:
New-NetRoute -DestinationPrefix "zero.zero.zero.zero/zero" -NextHop "192.168.2.2" -InterfaceIndex eight
To disable the IPv6 protocol for the community adapter:
Get-WebAdapterBinding -InterfaceAlias Ethernetzero | Set-WebAdapterBinding -Enabled:$false -ComponentID ms_tcpip6
Set-DnsClientServerAddress: Set Primary and Secondary DNS Server Addresses
In order to set the first and secondary DNS server IP addresses in Windows, use the Set-DNSClientServerAddress cmdlet. For instance:
Set-DNSClientServerAddress –InterfaceIndex eight –ServerAddresses 192.168.2.11,10.1.2.11
You can even set nameservers utilizing an array:
$dnsParams = @
After altering your DNS settings, you possibly can clear the resolver cache:
How to Change Static IP Address to DHCP utilizing PowerShell?
To permit the pc to acquire a dynamic IP handle from the DHCP server for the community adapter, run this command:
Set-NetIPInterface -InterfaceAlias Ethernetzero -Dhcp Enabled
Clear the DNS server settings:
Set-DnsClientServerAddress –InterfaceIndex eight -ResetServerAddresses
And restart your adapter with a purpose to receive an IP handle routinely from the DHCP server:
Restart-WebAdapter -InterfaceAlias Ethernetzero
If you beforehand had a default gateway configured, take away it:
Set-NetIPInterface -InterfaceAlias Ethernetzero| Remove-NetRoute -Confirm:$false
How to Remotely Change IP Address and DNS settings with PowerShell?
You can use PowerShell to remotely change IP handle or DNS server settings on a number of distant computer systems. Suppose, your activity is to vary DNS settings for all servers within the particular AD container (Organizational Unit). To get the record of computer systems within the script beneath, the cmdlet is used, and WinRM is used to hook up with computer systems remotely (the Invoke-Command cmdlet):
$Servers = Get-ADComputer -SearchBase ‘OU=Servers,OU=Berlin,OU=DE,DC=woshub,DC=cpm’ -Filter '(OperatingSystem -like "Windows Server*")' | Sort-Object Name
ForEvery ($Server in $Servers)