PowerShell for Netsh
Windows Server 2012 has vastly expanded PowerShell support
April 16, 2013
Netsh has long been a mainstay among Microsoft Windows Server management commands, and it wasn't until the recent release of Windows Server 2012—with its vastly expanded PowerShell support—that PowerShell was able to do the same sort of tasks that you've always needed the venerable netsh to complete. With Windows Server 2012 and PowerShell 3.0, there are almost 250 different networking cmdlets. In this Top 10, I'll show how to use PowerShell to perform 10 common tasks that previously required you to use netsh.
10. List network adapters—Perhaps the most basic network command is to list the network adapters. One nice bonus with the PowerShell command is that you can include the optional -IncludeHidden parameter to show hidden adapters that you can't see in the graphical interface. Here's the PowerShell cmdlet you need:
Get-NetAdapater
9. Disable and enable adapters—Another basic network adapter management function that PowerShell 3.0 allows is enabling and disabling the network adapter. Although I rarely do this on servers, it's pretty handy on laptops and tablets that have trouble connecting to different networks. The following commands will do the job for you:
Disable-NetAdapter -Name "Wireless Network Connection"Enable-NetAdapter -Name "Wireless Network Connection"
8. Show the system's TCP/IP information—The Get-NetIPConfiguration cmdlet shows the system's current TCP/IP configuration settings. You can see a system's current IPv4 and IPv6 addresses, the gateway address and its status, and DNS server addresses. Use the following command:
Get-NetIPConfiguration -Detailed
7. Rename a network adapter—You can rename network adapters by using PowerShell 3.0. However, you should be aware that you need to have administrative rights in order to execute this and other network configuration commands. Here's the command to rename network adapters:
Rename-NetAdapter -Name "Ethernet" -NewName "Public"
6. Set a new static IP address—To set the IP address of the network adapter named Ethernet to 192.168.100.115 and the gateway address to 192.168.100.1, use the following type of command—it's especially useful when you're configuring Windows Server Core:
$netadapter = Get-NetAdapter -Name Ethernet$netadapter | New-NetIPAddress -IPAddress 192.168.100.115 -PrefixLength 24 –DefaultGateway 192.168.100.1
5. Set a new DNS server address—When you change the system's IP address type, you often have to change the DNS servers as well. The following example shows how the Set-DNSClientServerAddress cmdlet can be used to configure a network adapter with a DNS server address of 192.168.100.8:
$netadapter = Get-NetAdapter -Name Ethernet$netadapter | Set-DNSClientServerAddress -ServerAddresses 192.168.100.8
4. Change the network adapter to use DHCP addressing—PowerShell can be used to reconfigure the system to use a DHCP assigned address. This command sets the IP address of the network adapter named Ethernet to use DHCP addressing:
$netadapter = Get-NetAdapter -Name Ethernet$netadapter | Set-NetIPInterface -Dhcp Enabled
3. Set theEthernet interface to use a DHCP assigned DNS address—When you switch to DHCP addressing, you typically want the DNS server address to be dynamically assigned as well. This command sets the Ethernet interface to use a DHCP assigned DNS address:
$netadapter = Get-NetAdapter -Name Ethernet$netadapter | Set-DnsClientServerAddress -InterfaceIndex 12 -ResetServerAddresses
2. Add a Windows Firewall rule—Just like netsh works with both the system's network configuration and the Windows Firewall configuration, the following PowerShell command shows how you can configure Windows Firewall to allow remote management:
Set-NetFirewallRule -DisplayGroup "Windows Firewall Remote Management" -Enabled True
1. Enable and disable Windows Firewall—Probably the most basic Windows Server commands are to enable and disable Windows Firewall. The following commands show how PowerShell can do just that:
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled TrueSet-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
About the Author
You May Also Like