Would you like to learn how to use a group policy to configure logon scripts using Powershell? This tutorial will show you how to create a group policy to run Powershell scripts during logon.

• Windows 2012 R2
• Windows 2016
• Windows 2019
• Windows 10
• Windows 11

Change the configuration to reflect your domain name.

Equipment list

Here you can find the list of equipment used to create this tutorial.

This link will also show the software list used to create this tutorial.

Tutorial GPO - Logon scripts using Powershell

On the domain controller, open the group policy management tool.

Windows - Group Policy management

Create a new group policy.

Windows 2012 - Group Policy Objects

Enter a name for the new group policy.

Windows - Add GPO

In our example, the new GPO was named: MY-GPO.

On the Group Policy Management screen, expand the folder named Group Policy Objects.

Right-click your new Group Policy Object and select the Edit option.

Windows - Edit GPO

On the group policy editor screen, expand the User configuration folder and locate the following item.

Copy to Clipboard

Access the option named Scripts.

GPO - User Startup scripts

Access the Logon configuration option.

GPO - User startup script

Add a new startup script.

Powershell - Startup script

Our configuration.

Copy to Clipboard

Create a Powershell script named MYSCRIPT inside the NETLOGON folder.

Copy to Clipboard

Here is the content of our script.

Copy to Clipboard

In our example, we are going to configure the user wallpaper.

In our example, we add a JPG file named WALLPAPER inside the NETLOGON directory.

Make sure the domain users have read-only permission over the script.

GPO - Logon script permission

To save the group policy configuration, you need to close the Group Policy editor.

Congratulations! You have finished the GPO creation.

Tutorial GPO - Logon scripts using Powershell

On the Group policy management screen, you need to right-click the Organizational Unit desired and select the option to link an existent GPO.

Windows-2012-Applocker application

In our example, we are going to link the group policy named MY-GPO to the root of the domain.

GPO- tutorial linking

After applying the GPO you need to wait for 10 or 20 minutes.

During this time the GPO will be replicated to other domain controllers.

On a remote computer, login as any user.

GPO - User Startup scripts powershell

The Powershell script will be silently executed.

In our example, we used a Powershell logon script to configure the user wallpaper.