PowerShell and logon Scripts

In this Tutorial we are going over the process to create a logon script using PowerShell and that will work for all systems running at least Windows Server 2008 R2 or Windows 7.


The script itself is pretty simple, basically we need to a simple one and save it as .ps1 (it does not be signed) and in the script below we are listing the services on a file (twice actually) and creating a folder called C:\Temp.


The next step to assign a script to the users is using Group Policies, we can create a new one or edit an existent one. Select the desired Group Policy and edit it.


In the new Group Policy, expand User Configuration, Policies, Windows Settings and click on Scripts (Logon/Logoff). Double click on Logon and on the new page click on PowerShell Scripts tab.


In order to use the script that created at the beginning of this Tutorial, we will be clicking on Show Files… and on the new window we are going to paste the script, as shown in the image below. After that, just close the window.


Back to the Logon Properties window, click on Add… and then Browse… select the script that we have just copied over which is logon.ps1 and click OK.


The final result is shown in the image below, before clicking okay, select Run Windows PowerShell scripts first  from the list.


Time to test it, wait the Active Directory replication to take place, and make sure that the user (since we configured that PowerShell Script at User Level inside of the OU, and to be executed during the logon) has the proper Group Policy associated to him.

After the user logs on the workstation/server, we can check if there is a service.csv file and also if the folder C:\Temp was created. If it was created successful, then we know that the PowerShell logon script is working like a charm.