commit 95c9f6ca03057b5901e2e83ea01b3182a74b8e91 Author: unknown <13404778+C9Glax@users.noreply.github.com> Date: Fri Mar 31 14:41:56 2023 +0200 initial commit diff --git a/GPU.xml b/GPU.xml new file mode 100644 index 0000000..fd3fa31 Binary files /dev/null and b/GPU.xml differ diff --git a/switchGPU.ps1 b/switchGPU.ps1 new file mode 100644 index 0000000..5f1f4a1 --- /dev/null +++ b/switchGPU.ps1 @@ -0,0 +1,53 @@ +param([String]$working=$pwd) +$folderPath = "C:\.gpu" +$gpuTask = Join-Path $folderPath GPU.xml +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -working $pwd" -Verb RunAs; exit } + +Write-Output "Testing if files exist" +if(-Not (Test-Path $folderPath)){ + Write-Output "Creating Directory $folderPath" + New-Item $folderPath -Type Directory +} +$scriptOld = Join-Path $working "switchGPU.ps1" +$scriptNew = Join-Path $folderPath "switchGPU.ps1" +if(-Not (Test-Path $scriptNew)){ + Write-Output "Copying script to $folderPath" + Copy-Item $scriptOld $scriptNew +} + + +Write-Output "Checking if task already exists" +if(Get-ScheduledTask | Where-Object{$_.TaskName -eq "GPU"}) +{ + Write-Output "Task exists" +}else +{ + Register-ScheduledTask -TaskName "GPU" -Xml (Get-Content $gpuTask | Out-String) +} + + +Write-Output "Waiting 5 Seconds" +Start-Sleep 5 +if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_10DE&DEV_1B80&SUBSYS_85AA1043&REV_A1\6&5c8cf2c&0&00080019"} | Where-Object{$_.Status -eq "OK"}) +{ + Write-Output "dGPU plugged in" + if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041"} | Where-Object{$_.Status -eq "OK"}) + { + Write-Output "Disabling iGPU" + pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU + }else + { + Write-Output "iGPU already disabled" + } +}else +{ + Write-Output "dGPU not plugged in" + if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041"} | Where-Object{$_.Status -eq "OK"}) + { + Write-Output "iGPU already enabled" + }else + { + Write-Output "Enabling iGPU" + pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU + } +}