Just for future reference in case someone else is trying to figure out how to do this heres the powershell code. Youll have to change your hardware ID to match your device(s) that you want to enable/disable but this will get you in the ballpark. In my case I was trying to disable a Razer Tartarus gamepad because my monitors wouldnt turn off when it was plugged in. I discovered that I had to not only disable the device under "keyboards" in device manager but I also had to disable the hardware ID for it that showed up under "Human Interface Devices" as well.
# Self-elevating PowerShell script to toggle the enabled state of a device
# Check to see if we are currently running "as Administrator"
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Definition + "'"
# Indicate that the process should be run as administrator
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated script
exit
}
# Function to toggle the device state by Hardware ID
function Toggle-DeviceStateByHardwareID {
param (
[string]$HardwareID
)
$device = Get-PnpDevice | Where-Object { $_.HardwareID -like "*$HardwareID*" }
if ($device -eq $null) {
Write-Host "No device found with Hardware ID: $HardwareID."
return
}
foreach ($dev in $device) {
if ($dev.Status -eq "OK") {
# Device is enabled, so disable it
$dev | Disable-PnpDevice -Confirm:$false
Write-Host "Device '$($dev.FriendlyName)' with Hardware ID: $HardwareID is now disabled."
} elseif ($dev.Status -eq "Error") {
# Device is disabled, so enable it
$dev | Enable-PnpDevice -Confirm:$false
Write-Host "Device '$($dev.FriendlyName)' with Hardware ID: $HardwareID is now enabled."
} else {
Write-Host "Device '$($dev.FriendlyName)' with Hardware ID: $HardwareID is in an unknown state."
}
}
}
# Toggle the devices using their Hardware IDs
Toggle-DeviceStateByHardwareID -HardwareID "USB\VID_1532&PID_0208&MI_01&JS_02"
Toggle-DeviceStateByHardwareID -HardwareID "HID\VID_1532&PID_0208&REV_0200&MI_02"