GPO to run login/startup script files


Sometimes I need to do things when the computer starts up or when a user logon. A good way to do that is with a GPO startup script or a GPO logon script.

Prepare GPO to copy files

1. Create a new GPO
image

2. Edit the GPO and go to: Computer Configuration –> Preferences –> Files
image

3. Right click the white area in the right pane and click New –> File
image

4. Action = Replace, Source file(s) = “The folder where you have you scripts.”, Destination folder = “The folder where you want to copy the scripts”, Archive = Yes.
image

5. Mark “Remove this item when it is no longer applied”. Click “Ok”
image

Then you need to link the policy to a OU.

You have now created a GPO the will copy the scripts to a local folder. The files will be download to the folder again if the user is deleting or changing the files.

Create GPO to run the files

Next we need to create a GPO that run the scripts

1. Create a new GPO
image

To create a Computer startup script

1. For computer startup scripts, go to: Computer Configuration –> Policies –> Windows Settings –> Scripts (Startup/Shutdown)
image

2. Double click on “Startup” on the right pane
image

3. Click “Add”
image

4. Choose the script that you have copied with the 1. GPO that we created and click “Ok”
image

5. Click “Ok”
image

You have now a script that will run from the C drive every time the computer starts

To create a User logon script

1. For user login scripts, go to: User Configuration –> Policies –> Windows Settings –> Scripts (Logon/Logoff)
image

2. Double click on “Logon” on the right pane

image

3. Click “Add”
image

4. Choose the script that you have copied with the 1. GPO that we created and click “Ok”
image

5. Click “Ok”
image

You have now a script that will run from the C drive every time a user is logging on.

 

I normally I add a delay in the scripts. Because then I sure that the computer have a network connection. In case the scripts needs to pull some setting or other stuff from the network.