Connect or Disconnect Network Adapter

by Apr 28, 2010

When you are ready to connect or disconnect a network adapter, you can utilize the Shell.Application COM object, which will give you access to context menu items.

$sa = New-Object -ComObject Shell.Application
$conn = $sa.NameSpace(49).Items() |
? { $_.Name -like '*T-Mobile*' }
if (($conn.verbs() |
Select-Object -ExpandProperty Name) -contains '&Connect') {
$verb = $conn.Verbs() | ? { $_.Name -eq '&Connect' }

This example will connect to your network connections folder (virtual ID 49), select an adapter with 'T-Mobile' in its name and call the &Connect context menu item. Unfortunately, verb names are localized and will need to be adjusted. You will also need to add the ampersand when appropriate, which marks the underlined keyboard shortcut in the context menu item.

Twitter This Tip! ReTweet this Tip!