Created
February 7, 2022 16:41
-
-
Save GleasonK/822457e90a7fe19a30cba59d9942de20 to your computer and use it in GitHub Desktop.
Useful Script for Surface Book 2 to toggle off GTX when attempting to detach the screen.
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
# Useful script for detaching the screen of Surface Book. | |
# Run if detach light blinks red indicating that it cannot be detached | |
# since applications are preventing the detach. | |
# | |
# Option 1: Copy-paste into powershell window. | |
# | |
# Option 2: Run as PowerShell script (requires execution policy change): | |
# https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts | |
# | |
Try { | |
$GtxId = (Get-PnpDevice -FriendlyName "*GTX*").InstanceId | |
echo " DeviceID = $GtxId" | |
echo "Disabling GTX." | |
Disable-PnpDevice -Confirm:$false -InstanceId $GtxId | |
Read-Host -Prompt "Safe to detach. Hit enter to re-enable." | |
echo "Enabling GTX." | |
Enable-PnpDevice -Confirm:$false -InstanceId $GtxId | |
} Catch { | |
$ErrorMessage = $_.Exception.Message | |
$FailedItem = $_.Exception.ItemName | |
echo "Try Run as Admin." | |
echo "ERROR: $ErrorMessage" | |
echo "ERROR: $FailedItem" | |
} Finally { | |
Read-Host -Prompt "Press any key to quit" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super handy script, thanks!!
Adapted it a bit, so that it automatically asks for admin permissions if necessary and also automatically toggles between enabling and disabling the GPU based on the device state, so the command doesn't need to be interactive, and you don't need to keep the PowerShell window open while in clipboard mode: