microsoft windows powershell

Automating changes with powershell is your goal.   You should be able to do this on local and cloud datacenters, like azure.  Azure is something you are studying right?  Taking the azure test 70-533?  Read here for azure test guide:

https://docs.google.com/document/d/1kt7drQtvMHk8nmgHj94lZLPWglT78hKrwvpFcqMTmEU/edit?usp=sharing

You should be able to run powershell commands locally and remotely.  You will need to master access control to do this well.  Administrator rights and UAC will put hurdles in your plan (or is that painful pitfalls?).  Using batch files to launch PS files will help.

Use “Invoke-Command” powershell cmd to run powershell commands on remote computers (like ones in azure).

Need to change network settings?   There are commands to change ip address in powershell, often interface index is needed.  The interface index is often difficult to validate.  For example, msinfo32.exe will show different network interface indexes than other windows commands!   I find this frustrating.  Netshell (netsh.exe) maybe more reliable way to change ip address settings on NICs. Interfacealias is availabe via get-netipinterface command.  Example:

PS C:\Windows\system32> Get-NetIPInterface
ifIndex InterfaceAlias                  AddressFamily NlMtu(Bytes) InterfaceMetric Dhcp     ConnectionState PolicyStore
——- ————–                  ————- ———— ————— —-     ————— ———–
21      Local Area Connection* 12       IPv6                  1500               5 Disabled Disconnected    ActiveStore
19      Ethernet 2                      IPv6                  1500               5 Disabled Disconnected    ActiveStore
14      isatap.home                     IPv6                  1280              50 Disabled Disconnected    ActiveStore
20      Wi-Fi 2                         IPv6                  1500              25 Enabled  Connected       ActiveStore
1       Loopback Pseudo-Interface 1     IPv6            4294967295              50 Disabled Connected       ActiveStore
21      Local Area Connection* 12       IPv4                  1500               5 Enabled  Disconnected    ActiveStore
19      Ethernet 2                      IPv4                  1500               5 Enabled  Disconnected    ActiveStore
20      Wi-Fi 2                         IPv4                  1500              25 Enabled  Connected       ActiveStore
1       Loopback Pseudo-Interface 1     IPv4            4294967295              50 Disabled Connected       ActiveStore

With this, we see ifIndex 20 = our wireless.  To change dns settings only for wireless,  at powershell prompt type:

Set-DnsClientServerAddress -InterfaceIndex 20 -ServerAddresses “8.8.8.8”

How do you set back to normal DHCP provided dns?  Use reset command:

Set-DnsClientServerAddress -InterfaceIndex 20 -ResetServerAddresses

How do you set the IP address with powershell, once you have the interface index?

Use this command:

New-NetIPAddress -InterfaceIndex 2 -IPAddress 200.100.10.1 -PrefixLength 24 -DefaultGateway 200.100.10.10

Interface indexes are not all the same. For example, msinfo32.exe will give a different interface index than “Get-NetIPInterface”

Copyright 2016 Rod Deluhery

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s