Part of my work routine involves frequently enabling/disabling network adapters in the device manager, which is tedious and time consuming. I am learning PowerShell, and want to write a simple script that automatically enables/disables the network adapter.
I am trying to use the WASP snap-in, which doesn't seem too difficult, but I cannot get it to work.
So far I have:
# Launch the Device Manager
$deviceManager = Show-ControlPanelItem -Name "Device Manager"
# Display all currently open windows. Device Manager should display as 'mmc'
Select-Window | ft -auto
# Select Device Manager as the active window
Select-Window mmc | Set-WindowActive
# Send input to device manager
Select-Window mmc | Send-Keys "{TAB}"
Select-Window mmc | Send-Keys "n"
If the keyboard inputs are read properly, Network Adapter should be highlighted in Device Manager. Instead, the device manager is opened and is active, but otherwise nothing happens.
What am I doing wrong? How do I send keyboard input properly using WASP? WASP is not required, I am open to other tools if a superior option is available.
Try working with
WMI
instead:This will give you a list of your adapters:
You can use a filter on
Name
to isolate a single adapter and assign the object to a variable:Then, you should be able to call
disable
,enable
,reset
, etc. on the object:Good luck!