Exploring the PowerCLI cmdlets – Get-NicTeamingPolicy

One of the new cmdlets from PowerCLU 4.0 Update 1 is Get-NicTeamingPolicy, so what does this do ?

It retrieves the Nic teaming policies of the specified virtual switches and virtual port groups, obviously !

So how can we use this cmdlet ?

Well, as it details the teaming policies of either a virtual switch or a portgroup then we will need to give it a…virtual switch or a portgroup, so how do we do this, lets try a one-liner:

Get-VMHost | Get-VirtualSwitch | Get-NicTeamingPolicy

This will do as it says on the tin, get a list of the hosts, for each of these it will get a list of virtual switches attached to the hosts and then list their nic teaming policies, the output is as so:

image

Not very user friendly hey !

So lets get this useful information into a nicer looking format, to do this we can choose the fields we want, add a few more extra items from the existing vmhost and vswitch objects to give us a more meaningful output:

Foreach ($VMHost in Get-VMHost){
Foreach ($vSwitch in ($VMHost |Get-VirtualSwitch )){
$NicTeaming = Get-NicTeamingPolicy -VirtualSwitch $vSwitch
$obj = new-object psobject
$obj |Add-Member -membertype NoteProperty -Name Host -value $VMHost
$obj |Add-Member -membertype NoteProperty -Name vSwitch -value $vSwitch
$obj |Add-Member -membertype NoteProperty -Name NumPorts -value $vSwitch.NumPorts
$obj |Add-Member -membertype NoteProperty -Name NumPortsAvailable -value $vSwitch.NumPortsAvailable
$PG = $vSwitch |Get-VirtualPortGroup
If ($PG.Count-gt 1){
$obj |Add-Member -membertype NoteProperty -Name PortGroups -value ([string]::join( ,,($PG)))
}
Else {
$obj | Add-Member -membertype NoteProperty -Name PortGroups -value $PG
}
$obj |Add-Member -membertype NoteProperty -Name BeaconInterval -value $NicTeaming.BeaconInterval
$obj |Add-Member -membertype NoteProperty -Name LoadBalancingPolicy -value $NicTeaming.LoadBalancingPolicy
$obj |Add-Member -membertype NoteProperty -Name NetworkFailoverDetectionPolicy -value $NicTeaming.NetworkFailoverDetectionPolicy
$obj |Add-Member -membertype NoteProperty -Name NotifySwitches -value $NicTeaming.NotifySwitches
$obj |Add-Member -membertype NoteProperty -Name FailbackEnabled -value $NicTeaming.FailbackEnabled
If ($NicTeaming.ActiveNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name ActiveNic -value ([string]::join( ,,($NicTeaming.ActiveNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name ActiveNic -value $NicTeaming.ActiveNic
}
If ($NicTeaming.StandbyNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name StandbyNic -value ([string]::join( ,,($NicTeaming.StandbyNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name StandbyNic -value $NicTeaming.StandbyNic
}
If ($NicTeaming.UnusedNic-gt 1){
$obj |Add-Member -membertype NoteProperty -Name UnusedNic -value ([string]::join( ,,($NicTeaming.UnusedNic)))
}
Else {
$obj |Add-Member -membertype NoteProperty -Name UnusedNic -value $NicTeaming.UnusedNic
}
$obj |Add-Member -membertype NoteProperty -Name CheckBeacon -value $NicTeaming.CheckBeacon
$obj
}
}

And the output now looks a little more friendly:

image

And if we want to make it even more friendlier to view then we can add it into VESI, it will of course be available in the next version of my PowerPack (due out soon)…

image

And don’t forget, with VESI it is easy to apply filters to the resulting output allowing you to easily check for inconsistencies in your teaming policies and vswitch settings…

image

One thought on “Exploring the PowerCLI cmdlets – Get-NicTeamingPolicy

  1. Pingback: Virtu-Al | Virtually everything is poshable

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.