This article describes on how to export the Native Windows Teaming Configuration to an XML file and import it back to recreate the team configuration.
Configuring the NIC teaming manually is a tedious task for the administrator where he has to identify the correct network adapters, team them, create additional team interfaces, assign VLAN IDs to them. Inbuilt PowerShell commands for creating and configuring the NIC team can be used for deployments, however when it comes to manage a dynamic environment, the deployment scripts also need to be kept up to date frequently to capture any changes in the environment.
Also, currently, there is no in-built mechanism in windows servers to export the teaming configuration, which can be used to do a complete NIC team restore in case of a disaster or OS reinstallation etc. This is where the scripts in this article will become useful as it can export the Native Windows Teaming Configuration to an XML file and import it back to recreate the team configuration anytime. This script can be readily used on any windows Server 2012 or Windows Server 2012 R2 Operating System, whether it’s on a physical server or virtual server.
Following are the details captured in the xml file for the export and import of configuration.
· Team names and number of teams
· Load balancing Algorithm for each team
· Team Members of each team
· Teaming Mode for each Team
· Standby Adapters per team
· Team interfaces per team
· VLAN ID for each team interface
The above details are exported to a structured XML file, which can be later used by the import_script.ps1 to restore the configuration.
Assumption: It is assumed that the same physical NICs are present in the server while doing the NIC team configuration export/import. The script exports the NIC names to the xml and hence the same NIC names should be present in the server while doing an import if the environment has customized NIC names. If the NIC teams or interfaces in the environment have special characters that interfere with XML tags, then the script needs to be modified with appropriate escape characters. Currently the script handles only whitespaces in the xml values.
1. Export the Team configuration
Now let’s have a high level overview of the ExportNICTeam.ps1. The following steps are commented in the PowerShell script at appropriate places to make it easily understandable.
Step1 – Specify the output xml file name to include the computername and get the number of teams.
Step2 – Create the xml Tags along with the Team Count information to be written to the xml file:
Based on the number of teams available in the system, the following step will be performed in a loop (Loop1)
Step3 – Get the details of each team into variables and append them to the xml file
Based on the number of VLAN interfaces available in each team, the following step will be performed in a loop (Loop2)
Step4 – List down the details of the VLAN interfaces for the team and append them to the xml file
Step5 – Close the XML tags to mark the end of file.
2. Import the Team configuration
The import script reads the values from the xml file and uses them as parameters for the PowerShell cmdlets to create team and modify the team properties.
Now let’s have a high level overview of the ImportNICTeam.ps1 script
Step1 – Specify the input xml file and load it to a variable
Step2 – Get the number of teams from the xml
Based on the number of teams available in the xml, the following step will be performed in a loop (Loop1)
Step3 – Collect all the attributes for creating a new team from the xml and identify the primary interface and its VLAN ID
Step4 – Create the new team with the primary interface details
Step5 – Set the standby NICs for the new team if present in the xml
Based on the number of VLAN interfaces available in each team, the following step will be performed in a loop (Loop2)
Step6 – Create VLAN interfaces for the non-primary Team Interfaces
The above steps 3 -6 will be repeated based on the number of teams in the configuration file.
The complete ExportNICTeam.ps1 and ImportNICTeam.ps1 scripts are shared here.
Additional Tip: The export script can be modified to point the output xml file to a shared location instead of default “C:\test\”. And this script can be executed on multiple machines remotely to have the teaming details of all the servers in the environment at a single location. This can be used later for recovery in case of a disaster.
Enhancement: This script can be further enhanced to include additional information such as TCP/IP configuration etc of the team interfaces.