Skip to content

Instantly share code, notes, and snippets.

@GleasonK
Created February 7, 2022 16:41
Show Gist options
  • Save GleasonK/822457e90a7fe19a30cba59d9942de20 to your computer and use it in GitHub Desktop.
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.
# 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"
}
@DavidGitter
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment