Find me in different places
« Configuring Exchange 2013 with Powershell- Part 2: Prerequisites | Main | Why Use Powershell? »

Configuring Exchange 2013 with Powershell- Part 1: Networking

When starting the process of configuring Exchange 2013 servers the first place I wanted to start was networking, I wanted to be able to just pass in some MAC addresses of the NICs and give them IPs, I also wanted everything to happen automatically. Using Powershell 3 made this easier then it used to be in older versions.

The first step to build 3 arrays. The first will hold the MAC address, the second the new names, the third the new IP addresses. An example can look like this:

[array]$macAddresses = "00-15-5D-00-0C-58","00-15-5D-00-0C-59",,"00-15-5D-00-0C-5A","00-15-5D-00-0C-5B","00-15-5D-00-0C-5C","00-15-5D-00-0C-5D"
[array]$nicNames =    "Management", "DAG", "iSCSI 1", "iSCSI 2", "iSCSI 3", "iSCSI 4"
[array]$ipAddresses = "", "", "", "", "", ""

The second is to make a loop that will go through and configure the NICs. One thing to note: make sure you have exactly the same number of data in all 3 loops in the correct order otherwise the NICs will be incorrectly configured.

for($i=0; $i -lt $macaddresses.Length; $i++){         
     [string]$macaddress = $macAddresses[$i]          
     Get-NetAdapter | Where-Object {$_.MacAddress -eq "$macaddress"} | Rename-NetAdapter -NewName $nicNames[$i] 
     New-NetIPAddress -InterfaceAlias $nicNames[$i] -IPAddress $ipAddresses[$i] -PrefixLength 24 

This loop will through and name the NIC based on the corresponding MAC address and then give it the IP , also setting the subnet mask. All of the cmdlets going forward are based on the interface name, it is crucial to have the interface name set correctly.

Now being able to change the name and IP is cool, but what about all of the other things that needs to get done to an interface? DNS, Jumbo packets? We can do all of that in Powershell! For example for a DAG NIC, you might want to do the following:

Set-DnsClient -InterfaceIndex DAG -RegisterThisConnectionsAddress: $false
#Disables NIC features for replication network that are not needed
Set-NetAdapterBinding -Name DAG -DisplayName "Client*" -Enabled $false
Set-NetAdapterBinding -Name DAG -DisplayName "File*" -Enabled $false

How about for the iSCSI network?

Set-DnsClient -InterfaceIndex iSCSI -RegisterThisConnectionsAddress: $false
#Enable Jumbo Packets
Set-NetAdapterAdvancedProperty -Name iSCSI -RegistryKeyword “*JumboPacket” -Registryvalue 9014

Now lets put it all together as one script:

[array]$macAddresses = "00-15-5D-00-0C-58","00-15-5D-00-0C-59",,"00-15-5D-00-0C-5A","00-15-5D-00-0C-5B","00-15-5D-00-0C-5C","00-15-5D-00-0C-5D"
[array]$nicNames =    "Management", "DAG", "iSCSI 1", "iSCSI 2", "iSCSI 3", "iSCSI 4"
[array]$ipAddresses = "", "", "", "", "", ""

for($i=0; $i -lt $macaddresses.Length; $i++)
     [string]$macaddress = $macAddresses[$i]
     Get-NetAdapter | Where-Object {$_.MacAddress -eq "$macaddress"} | Rename-NetAdapter -NewName $nicNames[$i] 
     if($nicNames[$i] -eq "Management")
         New-NetIPAddress -InterfaceAlias $nicNames[$i] -IPAddress $ipAddresses[$i] -PrefixLength 22 -DefaultGateway
         Set-DnsClientServerAddress -InterfaceAlias $nicNames[$i] -ServerAddresses,
     if($nicNames[$i] -like "DAG")
        Set-DnsClient -InterfaceIndex $nicNames[$i] -RegisterThisConnectionsAddress: $false
        New-NetIPAddress -InterfaceAlias $nicNames[$i] -IPAddress $ipaddresses[$i] -PrefixLength 28
        #Disables NIC features for replication network
        Set-NetAdapterBinding -Name $nicNames[$i] -DisplayName "Client*" -Enabled $false
        Set-NetAdapterBinding -Name $nicNames[$i] -DisplayName "File*" -Enabled $false                
     if($nicNames[$i] -like "iSCSI")
       Set-DnsClient -InterfaceIndex $nicNames[$i] -RegisterThisConnectionsAddress: $false
       New-NetIPAddress -InterfaceAlias $nicNames[$i] -IPAddress $ipaddresses[$i] -PrefixLength 24
       #Enables Jumbo Packets for iSCSI NICS only
       Set-NetAdapterAdvancedProperty -Name $nicNames[$i] -RegistryKeyword “*JumboPacket” -Registryvalue 9014
write-host "Configured NIC:"$nicnames[$i]

So by running this 32 line script you can guarantee that all of you NICs are configured correctly. It is also much faster then manually doing each step.

As I have said before, my ideas may not follow best practices, make sure you do your research to make sure configure your adapters correctly.

In my next post I will talk about installing the prerequisites for Exchange 2013

NOTE: You will either need to be running Server 2012 or have already installed WRM 3.0 to use these cmdlets

PrintView Printer Friendly Version

EmailEmail Article to Friend

References (4)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>