Run Windows PowerShell scripts first at logon, logoff, startup, shutdown
If you want to run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown, here is what you will have to do. You can prioritize Windows PowerShell scripts before non-PowerShell scripts using Local Group Policy Editor and Registry Editor.
When a user logs on or starts up the computer, all the scripts run simultaneously. It may cause some delay in the startup or running a specific program. It is often required to run all the Windows PowerShell scripts and Group Policy Object to run before non-PowerShell scripts.
Run Windows PowerShell scripts first
To run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown, follow these steps-
- Press Win+R.
- Type gpedit.msc and hit the Enter button.
- Go to Scripts in Computer Configuration.
- Double-click on Run Windows PowerShell scripts first at user logon, logoff.
- Select the Enabled option.
- Click Apply and OK.
- Double-click on Run Windows PowerShell scripts first at computer startup, shutdown.
- Select the Enabled option.
- Click Apply and OK.
Let’s check out these steps in detail.
At first, you will have to open the Local Group Policy Editor. For that, press Win+R, type gpedit.msc
, and hit the Enter button. After opening it, navigate to the following path-
Computer Configuration > Administrative Templates > System > Scripts
You will see two settings called:
- Run Windows PowerShell scripts first at user logon, logoff,
- Run Windows PowerShell scripts first at computer startup, shutdown.
Double-click on each of them, and select the Enabled option.
Click the Apply and OK to save the change.
Run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown using Registry Editor
To run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown using Registry Editor, follow these steps-
- Press Win+R.
- Type regedit and hit the Enter button.
- Click the Yes button.
- Go to System in HKLM.
- Right-click on System > New > DWORD (32-bit) Value.
- Name it as RunUserPSScriptsFirst.
- Double-click on it and set the Value data as 1.
- Click the OK button.
- Right-click on System > New > DWORD (32-bit) Value.
- Name it as RunComputerPSScriptsFirst.
- Double-click on it to set the Value data as 1.
- Click OK to save the change.
To know more, keep reading.
Before getting started, it is recommended to backup all Registry files and create a System Restore point.
Press Win+R to open the Run prompt, type regedit
, and hit the Enter button. If the UAC prompt appears, click the Yes button. After that, navigate to this path-
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem
Here you will have to create two REG_DWORD values. For that, right-click on System > New > DWORD (32-bit) Value and name it as RunUserPSScriptsFirst.
Double-click on it and set the Value data as 1.
Follow the same steps to create another DWORD (32-bit) Value and name it as RunComputerPSScriptsFirst. Then, set the Value data as 1.
RunUserPSScriptsFirst represents the Run Windows PowerShell scripts first at user logon, logoff setting, whereas RunComputerPSScriptsFirst defines the Run Windows PowerShell scripts first at computer startup, shutdown setting.
In case you want to revert these changes, you can follow these steps.
If you have done it using the Local Group Policy Editor, open the same path and select the Not Configured option. If you have done it using the Registry Editor, open the same System key and delete those two REG_DWORD values. To remove them, right-click on each of them, select the Delete option, and confirm it by clicking the OK button.
Hope it helps.