How to assign IP address to network interface using powershell.
First we need to load powershell module responsible for managing Network Adapters:
Import-Module NetAdapter
Then we need to list all avaliable Ethernet adapters:
Get-NetAdapter -Name Ethernet
then we will assign our Ethernet adapters into powershell variable.
$netadapters = Get-NetAdapter -Name Ethernet
in this varialbe we store collection of Network Adapters, if we have more then one we need to get exactly one that we are intersted in:
$myNetAdapter = $netadapters[0]
This grab first(0) network card and assign it to $mynetadapter. if you would like to select another one just put any valid number in [] ex. $netadapters[1] for 2nd card.
Now $myNetAdapter is holding out network card.
First we need to diable DHCP:
$myNetAdapter | Set-NetIPInterface -DHCP Disabled
Then Configure the IP address and default gateway.
$myNetAdapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.0.0.1 -PrefixLength 8 -Type Unicast -DefaultGateway 10.0.0.1
Finally we need to setup out DNSes:
Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 10.0.0.1

Hint:
Very often we would not like to have all ethernet interface named “Ethernet” to change it allias (for later use) we type:
$myNetAdapter.InterfaceAlias = "Internal Network"
This “renamed” out Ethernet interfaceto to Internal Network
I hope that this was useful for you, if yes, leave me comment!