Weekend Scripter: Use PowerShell to Discover Switch Extensions


Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to discover virtual switch extensions in Hyper-V.

Microsoft Scripting Guy, Ed Wilson, is here. I have been playing around with Windows PowerShell and with Hyper-V. One of the cool things about Hyper-V networking is that the virtual switches are extensible. This provides a great space for third-party networking features. But there are a couple of virtual switch extensions that ship with the product that are pretty cool. These extensions are shown in the following image.

Image of menu

I can use Windows PowerShell to discover these switch extensions by using the Get-VMSwitchExtension cmdlet. Because I enable switch extensions on a per virtual switch basis, I need to supply the name of the virtual switch to the cmdlet as shown here:

PS C:\> Get-VMSwitchExtension -VMSwitchName externalswitch

 

Id                  : EA24CD6C-D17A-4348-9190-09F0D5BE83DD

Name                : Microsoft NDIS Capture

Vendor              : Microsoft

Version             : 6.3.9600.16384

ExtensionType       : Monitoring

ParentExtensionId   :

ParentExtensionName :

SwitchId            : 3341a008-4cab-460d-ae95-5acc640d9598

SwitchName          : externalSwitch

Enabled             : False

Running             : False

ComputerName        : EDLT

Key                 :

IsDeleted           : False

 

Id                  : E7C3B2F0-F3C5-48DF-AF2B-10FED6D72E7A

Name                : Microsoft Windows Filtering Platform

Vendor              : Microsoft

Version             : 6.3.9600.16384

ExtensionType       : Filter

ParentExtensionId   :

ParentExtensionName :

SwitchId            : 3341a008-4cab-460d-ae95-5acc640d9598

SwitchName          : externalSwitch

Enabled             : True

Running             : True

ComputerName        : EDLT

Key                 :

IsDeleted           : False

Because this is Windows PowerShell, it means that the cmdlets behave in the same manner. This means that I can use the Get-VMSwitchExtension cmdlet to retrieve the names of all the virtual switches on the host machine. I can feed those results to the –VMSwitchName parameter to retrieve the extension information. I then decide to choose the name of the extension, the switch name and whether the extension is enabled and running. I then sort the results. The command is shown here:

Get-VMSwitchExtension -VMSwitchName (get-vmswitch).name |

select name, switchname, enabled, running | sort enabled, running

The command and the output are shown in the image that follows:

Image of command output

Suppose I need to perform a network trace on one of my virtual machines for diagnostic purposes. I can enable the Microsoft NDIS capture extension. First I need to check to see the status of the extension. I use wildcard characters to reduce typing, and I achieve the following command.

PS C:\> Get-VMSwitchExtension -VMSwitchName externalswitch -Name *ndis*

 

Id                  : EA24CD6C-D17A-4348-9190-09F0D5BE83DD

Name                : Microsoft NDIS Capture

Vendor              : Microsoft

Version             : 6.3.9600.16384

ExtensionType       : Monitoring

ParentExtensionId   :

ParentExtensionName :

SwitchId            : 3341a008-4cab-460d-ae95-5acc640d9598

SwitchName          : externalSwitch

Enabled             : False

Running             : False

ComputerName        : EDLT

Key                 :

IsDeleted           : False

Now I need to enable the extension. To do this, I simply pipel the previous command to the Enable-VMSwitchExtension. This is shown here:

PS C:\> Get-VMSwitchExtension -VMSwitchName externalswitch -Name *ndis* | Enable-VMSw

itchExtension

 

Id                  : EA24CD6C-D17A-4348-9190-09F0D5BE83DD

Name                : Microsoft NDIS Capture

Vendor              : Microsoft

Version             : 6.3.9600.16384

ExtensionType       : Monitoring

ParentExtensionId   :

ParentExtensionName :

SwitchId            : 3341a008-4cab-460d-ae95-5acc640d9598

SwitchName          : externalSwitch

Enabled             : True

Running             : False

ComputerName        : EDLT

Key                 :

IsDeleted           : False

Join me tomorrow when I will talk about more cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Comments (1)

  1. Chen V says:

    Very handy for Admins.

Skip to main content