Powershell : Basic setup

As soon as a new OS is setup up on my server, I try to do first these 2 things : creating a nic team and set it an IP and a DNS. Of course I would like to manage it remotely and this means I have to activate a bunch of different services and open a few ports in my firewall. But because I don’t use a GUI, I have to do it via Powershell. And it always seems to be a little bit complicated.

Setting the network adaptaters

Here is how I do it :
First and foremost, I have to get the names of my net adapters :

Get-NetAdapter

It will return a list of network adapters :

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
NIC2                      Realtek PCIe GBE Family Controller #2         4 Up           00-01-2E-56-5E-06         1 Gbps
NIC1                      Realtek PCIe GBE Family Controller            6 Up           00-01-2E-56-5E-06         1 Gbps
Team1                     Microsoft Network Adapter Multiplexo...       3 Up           00-01-2E-56-5E-06         2 Gbps

Just note their names so that you will be able to join them together.
Now create a team this way :

new-NetLBFOTeam TEAM1 “Ethernet”, “Ethernet 2” -TeamingMode SwitchIndependant -LoadBalancingAlgorithm HypervPort

You can of course ignore these 2 last parameters. I just set them this way because my Windows Server is a hypervisor.
The next thing I generally do is to define an IP adress to this nic and I set a DNS server address :

New-NetIPAddress –InterfaceAlias “TEAM1” –IPAddress 172.29.22.6 –PrefixLength 27 -DefaultGateway 172.29.22.1
Set-DnsClientServerAddress -InterfaceAlias “TEAM1” -ServerAddresses 172.29.22.2,172.29.22.3

Enabling remote administration

If I want to connect myself remotely via RSAT or via Powershell I must :

  1. Set my local area as a private and secured network
  2. Open the required ports in my firewall
  3. Enable remote Powershell connections

To do so :

Get-NetConnectionProfile

You should get something like this :

Name : Réseau
InterfaceAlias : Team1
InterfaceIndex : 3
NetworkCategory : Public
IPv4Connectivity : Internet
IPv6Connectivity : NoTraffic


and to change this to private or domain :

Set-NetConnectionProfile –InterfaceAlias “TEAM1” -NetworkCategory Private

And because I’m too lazy to show you which services to allow or ports to open, lets do this :

Enable-NetFirewallRule *

Then on both Windows Computers(the client and the server) :

Enable-PSRemoting -Force
Set-Item wsman:\localhost\client\trustedhosts *
Restart-Service WinRM

And if you want to test if everything is alright, just try to connect yourself via RSAT or Powershell.
Via powershell:

Enter-PSSession 172.29.22.6 -Credential Administrator

Leave a Reply

Your email address will not be published. Required fields are marked *