How can I create a desktop shortcut that runs PowerShell device commands in sequence?

0
1
Asked By MapleOrbit47 On

I want one desktop shortcut to run three PowerShell commands sequentially: enable my GPU device, wait for that operation to finish, disable it, and then enable it again. I already have separate shortcuts that work independently, but I'm not sure how to combine them into one reliable sequence. The device instance ID is `PCIVEN_1002&DEV_73DF&SUBSYS_52101849&REV_C56&399090B&0&00000019`. The commands use `Enable-PnpDevice` and `Disable-PnpDevice` with confirmation disabled. This is a workaround for recurring GPU crashes, so the shortcut may need to run with administrator privileges.

2 Answers

Answered By QuietCedar82 On

Put the commands in a PowerShell script rather than trying to chain separate shortcut targets. Save this as something like `Reset-Gpu.ps1` and run the shortcut as administrator:

```powershell
$deviceId = 'PCIVEN_1002&DEV_73DF&SUBSYS_52101849&REV_C56&399090B&0&00000019'

Enable-PnpDevice -InstanceId $deviceId -Confirm:$false
Start-Sleep -Seconds 2
Disable-PnpDevice -InstanceId $deviceId -Confirm:$false
Start-Sleep -Seconds 2
Enable-PnpDevice -InstanceId $deviceId -Confirm:$false
```

Set the shortcut target to:

```text
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -ExecutionPolicy Bypass -File "C:PathToReset-Gpu.ps1"
```

Open the shortcut’s Properties, choose Advanced, and enable “Run as administrator.” The device-management cmdlets generally require elevation.

PixelHarbor6 -

Adding a short delay between operations is useful here. Without it, Windows may still be processing the first device state change when the next command starts.

Answered By SilverQuill29 On

You can also place the commands in a `.bat` file and call PowerShell once, but a `.ps1` script is cleaner and makes the order explicit. If you use a batch file, the important part is to invoke PowerShell with a single command string and separate the commands with semicolons. Make sure the batch file or its shortcut is launched as administrator; otherwise the enable and disable operations may fail silently or return an access-denied error.

MapleOrbit47 -

That explains why my individual shortcuts worked inconsistently. I’ll use the script approach and run the shortcut elevated.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.