I recently came across the need to configure IP information on a Network interface using a script. This is definitely something that can be accomplished with NETSH, but I was looking for a way to do it with native PowerShell using Get-WmiObject. If there is a choice, I tend to prefer to stick with native Powershell Cmdlets and functions rather than running cmd based tools, but that is just my personal opinion and you can take it or leave it.
My goal was to be able to specify a Network Interface by name, ie “Local Area Connection” and pass it an IP address, mask, gateway, and 1 or 2 DNS servers. In order to accomplish this there were two WMI classes that I needed. The first is Win32_NetworkAdapter. The second is Win32_NetworkAdapterConfiguration. The real key (pun intended) was to figure out a way to join the information from these two classes so that I knew for sure that I was working with the same network interface. It turns out that both classes have a property called InterfaceIndex.
Win32_NetworkAdapter has a property called netconnectionid which is equal to the name of the Adapter, ie “Local Area Connection”.
With that information, here is a function that you can use to specify settings for a NIC based on the name of the NIC.
Hope you find this useful.