Editing device manager with powershell
Part of my workflow involves frequently enabling / disabling network adapters in Device Manager, which is tedious and time consuming. I'm learning PowerShell and I want to write a simple script that automatically enables / disables a network adapter.
I'm trying to use a WASP snap, which doesn't seem too complicated, but I can't seem to 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 correctly, the network adapter should be highlighted in Device Manager. Instead, Device Manager opens and is active, but otherwise nothing happens.
What am I doing wrong? How do I properly send keyboard input using WASP? WASP is not required, I am open to other tools if a superior option is available.
source to share
Try WMI
working with WMI
:
This will give you a list of your adapters:
Get-WmiObject -Class Win32_NetworkAdapter
You can use filter on Name
to isolate one adapter and assign the object to a variable:
$adapter = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%MyAdapterName%'"
You can then call disable
, enable
, reset
etc. on the object:
$adapter.disable()
Good luck!
source to share