Last active
December 28, 2023 14:06
-
-
Save neo-razgriz/3980655380fb7e0eea7b7def6633b26b to your computer and use it in GitHub Desktop.
Disable and Enable GameDAC Game to make it appear on the Output Devices list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([switch]$Elevated) | |
# Run elevated powershell that can execute scripts | |
# Source: https://superuser.com/questions/108207/how-to-run-a-powershell-script-as-administrator | |
function Test-Admin { | |
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
if ((Test-Admin) -eq $false) { | |
if ($elevated) { | |
# tried to elevate, did not work, aborting | |
} else { | |
# $NoExit = "-noexit" # Uncomment for debugging | |
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-executionpolicy bypass -noprofile {1} -file "{0}"' -f ($myinvocation.MyCommand.Definition, $NoExit)) | |
} | |
exit | |
} | |
# My Code starts here | |
function Get-PNPs { | |
Get-PnpDevice -Status OK -FriendlyName "*GameDAC Game*" | |
} | |
$ExpectedPNPs = 3 | |
$MaxRetries = 4 | |
for (($Retries=0), ($GameDACGamePNPs = Get-PNPs); $GameDACGamePNPs.Count -lt $ExpectedPNPs -and $Retries -lt $MaxRetries; ($Retries++), ($GameDACGamePNPs = Get-PNPs)) { | |
'GameDAC Game problem found, disabling...' | |
Get-PnpDevice -Class Media -FriendlyName "GameDAC Game" | Disable-PnpDevice -Confirm:$false | |
Sleep 3 | |
'enabling...' | |
Get-PnpDevice -Class Media -FriendlyName "GameDAC Game" | Enable-PnpDevice -Confirm:$false | |
Sleep 3 | |
} | |
if ($GameDACGamePNPs.Count -lt $ExpectedPNP) { | |
'Failed to fix the problem.' | |
} else { | |
'Problem is fixed.' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment