Windows – One-gesture solution to disable/enable a device in device manager (without a third-party tool)

device managerscriptwindows 10

To overcome an annoying bug in Windows 10, I found a solution. The problem is, it's a lot of clicking and I'd like to automate the steps (script?) if possible. Here's the context from Reddit:

There is an easier fix though than restarting, if you go to Device Manager, then under Sound, Video and Game controllers, find: Intel Display Audio and disable then re-enable and it should fix it.

There is an answer showing how to do this at the command-line with a third-party tool (devcon). But I'm not happy to install/maintain it and not even sure if it works in Windows 10. I'd like to be able to do this without any third-party tools.

It doesn't have to be a command-line script. I'd just like to be able to do this in a single gesture (double-click of a desktop icon is fine, maybe a Cortana command can do it?).

Best Answer

Based on my research and as the command works for you (as per your comment), here is the final script that may work as 'one gesture'. I've added at the begining some instruction to run as admin automatically (self elevated). This will only works if the user is admin of the computer, of course.

The final script, you may save as '.ps1' file, and execute with PowerShell :

# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)

# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
{
    # We are running "as Administrator" - so change the title and background color to indicate this
    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
    $Host.UI.RawUI.BackgroundColor = "DarkBlue"
    clear-host
}
else
{
    # 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 = $myInvocation.MyCommand.Definition;

    # Indicate that the process should be elevated
    $newProcess.Verb = "runas";

    # Start the new process
    [System.Diagnostics.Process]::Start($newProcess);

    # Exit from the current, unelevated, process
    exit
}
Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Disable-PnpDevice -confirm:$false
Get-PnpDevice -FriendlyName "Intel(R) Display Audio" | Enable-PnpDevice -confirm:$false
Related Question