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.

Solution


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.

image[2]

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.

image[5]

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.

image[8]

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.

image[11]

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.

image[14]

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

image[17]

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.

image[20]

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

Managing Hyper-V Server remotely through PowerShel... Working with PowerShell can be very common for daily tasks and Hyper-V Server management. However, as there is more than one server to be managed, som...
Managing Federation Services–Creating a GPO to sup... In this Tutorial we are going over the process to create a Group Policy to be applied to user objects, and this policy will add the Federation Servers...
Performing daily task with PowerShell to manage Hy... As a virtualization administrator, you will come across a lot of scenarios where you will need to create, modify, move, export, and other tasks to man...
Checking if a mailbox is valid using Exchange Mana... In some scenarios we need to check if a mailbox database is valid on Exchange Server, this kind of validation is useful when migrating/transitioning m...