A Windows Server 2022 administrator is creating a PowerShell script that will
stop a custom service,
apply a security patch,
restart the same service.
The script must run automatically every time the server is shut down for scheduled maintenance and must execute with Local System privileges without requiring any ongoing user interaction. Which implementation method best meets these requirements with the least administrative overhead?
Assign the script as a computer Shutdown script in Local (Group) Policy under Computer Configuration > Windows Settings > Scripts (Startup/Shutdown).
Add the script path to the PowerShell $Profile of the built-in Administrator account so it executes whenever that user starts a shell.
Copy a shortcut to the script into C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup so it launches during startup and shutdown.
Create a Scheduled Task that triggers on User Logoff and runs the script with the highest privileges.
Shutdown scripts configured through Local or Domain Group Policy (Computer Configuration > Windows Settings > Scripts - Shutdown) are processed automatically whenever the operating system enters the shutdown phase. Windows executes these scripts in the Local System context, providing the elevated rights needed to stop services, install updates, and restart services without additional credentials. Once linked, no further scheduling or profile changes are required.
A Scheduled Task tied to User Logoff does not fire during a system shutdown that occurs with no interactive user session and therefore would be unreliable. PowerShell profile files run only when the specified user launches a PowerShell session, not during an unattended shutdown. Placing a script in the common Startup folder causes it to execute after boot, not during shutdown, and offers no guarantee of Local System privileges. Hence, the Group Policy shutdown-script mechanism is the most suitable solution.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a Group Policy Shutdown Script?
Open an interactive chat with Bash
Why does a Scheduled Task triggered on User Logoff not work during shutdown?
Open an interactive chat with Bash
What is the difference between running a script using PowerShell $Profile and a Group Policy Shutdown Script?