Editing device manager using powershell

2.9k Views Asked by At

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.

1

There are 1 best solutions below

1
On

Try working with WMI instead:

This will give you a list of your adapters:

Get-WmiObject -Class Win32_NetworkAdapter

You can use a filter on Name to isolate a single adapter and assign the object to a variable:

$adapter = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%MyAdapterName%'"

Then, you should be able to call disable, enable, reset, etc. on the object:

$adapter.disable()

Good luck!