Date posted: 15 Jul 2020, 0 minutes to read

Register a Startup or Shutdown script on Windows with PowerShell

Today I got asked how you could register a Startup and/or Shutdown script on Windows through PowerShell. My colleague already had a setup for creating a VM, but wanted this extra step as well.

Searching the web revealed some bits and pieces, so I’m logging it here for future reference.

Nurturing plants image

Photo by Daniel Öberg


I’ve created this gist with the registration script and an example file with a script to execute on Startup or Shutdown of the VM. It will then log the date/time to a text file for easy testing:

Log messages in output text file

The trick is to set up (quite a lot of registry keys) and a windows folder that has to be present to get things working.


Tested on a Windows 10 VM (1909).


You need to run the register script with an elevated session because you need to have access to at least the %SYSTEMROOT% directory.