Exploring the PowerCLI cmdlets – Get-NicTeamingPolicy Part 2

In my previous post “Exploring the PowerCLI cmdlets – Get-NicTeamingpolicy” I showed you how to output some great looking information for vSwitches which detailed all the information we may ever need to know, so whilst on the same cmdlet lets look at PortGroups, these have the same type of settings and the same cmdlet also works against a PortGroup object, as before we can display this information with a single one liner…

Get-VMHost |Get-VirtualSwitch |Get-VirtualPortGroup |Get-NicTeamingPolicy

image

And again, this information is not great for reporting but fantastic for passing along the pipeline and using in a script, lets see if we can through some more useful information in there and try and get a nice looking output…

Foreach ($VMHost in Get-VMHost){
Foreach ($vSwitch in ($VMHost |Get-VirtualSwitch )){
Foreach ($PortGroup in ($vswitch |Get-VirtualPortGroup)){
$NicTeaming = Get-NicTeamingPolicy -VirtualPortGroup $PortGroup
$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 PortGroup -value $PortGroup
$obj |Add-Member -membertype NoteProperty -Name VLAN -value $PortGroup.VLanId
$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 IsLoadBalancingInherited -value $NicTeaming.IsLoadBalancingInherited
$obj |Add-Member -membertype NoteProperty -Name IsNetworkFailoverDetectionInherited -value $NicTeaming.IsNetworkFailoverDetectionInherited
$obj |Add-Member -membertype NoteProperty -Name IsNotifySwitchesInherited -value $NicTeaming.IsNotifySwitchesInherited
$obj |Add-Member -membertype NoteProperty -Name IsFailbackInherited -value $NicTeaming.IsFailbackInherited
$obj |Add-Member -membertype NoteProperty -Name IsFailoverOrderInherited -value $NicTeaming.IsFailoverOrderInherited
$obj |Add-Member -membertype NoteProperty -Name IsCheckBeaconInherited -value $NicTeaming.IsCheckBeaconInherited
$obj |Add-Member -membertype NoteProperty -Name BeaconInterval -value $NicTeaming.BeaconInterval
$obj |Add-Member -membertype NoteProperty -Name CheckBeacon -value $NicTeaming.CheckBeacon
$obj
}
}
}

image

Now doesn’t that look nicer !  But as before we can get the real benefits from adding this into VESI/PowerGUI, in there we can filter on the information, ensuring each of our portgroups across all of our servers are set exactly the same, both a plus on the configuration side as well as the security side…

image

This will of course also be available as part of V3 of my PowerPack, coming soon !

Leave a Reply

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