PowerShell and logon Scripts

Share this:

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.


Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).

Related Post

How to install Microsoft Azure PowerShell In this Tutorial we are going over the process to install Microsoft Azure PowerShell and we can use the same procedure to update several other compone...
Running PowerShell on Mac OS PowerShell for everyone! In this Tutorial we are going the installation process on Mac OS.SolutionThe first step is to download the .pkg file which is...
Listing the drive letters, size and free space usi... Using PowerShell, the administrator is able to retrieve a lot of information from the operating system. In Today’s Tutorial, we are going the process ...
How to activate synchronization in Office365 We are going over the process to enable synchronization in the new Office 365 Administration Center and also using PowerShell.  Solution In s...