PowerShell setting a static IP

English: Screenshot of Windows PowerShell 1.0 ...
English: Screenshot of Windows PowerShell 1.0 Deutsch: Screenshot von Windows PowerShell 1.0 فارسی: عکس صفحه‌ی نمایش از ویندوز پاورشل نسخه‌ی 1.0 Русский: Сессия в Windows PowerShell (Photo credit: Wikipedia)

In an effort to force myself to learn/use powershell I installed a core install of Server 2012 for my WSUS. Here’s how you change the IP Address:

from the CMD prompt, ps.exe to get poweshell. If you’ve closed your command prompt, log off and back on, or press Ctrl+Alt+Del and start task manager, then run cmd and/or PS.exe

Changing the IP
# Import the NetAdapter module. This step is provided for clarity. It is not needed due to the new module autoloading feature in Windows PowerShell 3.0

Import-Module NetAdapter

# Retrieve the network adapter that you want to configure.

$netadapter = Get-NetAdapter -Name Ethernet

# Disable DHCP.

$netadapter | Set-NetIPInterface -DHCP Disabled

# Configure the IP address and default gateway.

$netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.0.1.100 -PrefixLength 24 -Type Unicast -DefaultGateway 10.0.1.1

# Configure the DNS client server IP addresses.

Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 10.0.1.10

If you screw up, do:  Remove-NetIPAddress -interfaceindex

Got this from: http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/21/use-powershell-to-configure-the-nic-on-windows-server-2012.aspx

Advertisements