Powershell Logon Script Failing

Posted on 2014-07-15
Medium Priority
Last Modified: 2014-09-17
I am testing logon scripts pushed out through a GPO linked to a specific OU.

Its a simple script that just enters the user name into a remote SQL server I set up on the domain.

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Data Source=MYSERVER;Initial Catalog=data;Integrated Security=SSPI;"
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.connection = $conn
$cmd.commandtext = "INSERT INTO tbl_Logon(username) VALUES('{0}')" -f $env:username

The script does not run automatically but once logged in, I can launch it on the target computer/user from the command line using the following:

Powershell.exe -File \\my-domain.com\NETLOGON\myscript.ps1

and the data is inserted into the table. RSOP does show the correct path and executable name so I know the policy is right, so what am I missing? Why won't it run automatically when I login?

Question by:spencerturbine
  • 5
  • 4
LVL 29

Expert Comment

ID: 40197546
Is the GPO configured at:
Computer Configuration/Windows Settings/Scripts/Startup

Author Comment

ID: 40197697
No, this is a logon script, not a startup script.
LVL 29

Expert Comment

ID: 40197717
Is this the only script ?

Or are there others that run, but just not this one  ?
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.


Author Comment

ID: 40197727
This is the only script.
LVL 29

Accepted Solution

becraig earned 2000 total points
ID: 40197756
Here is some good reading to make sure you have it setup correctly:

See section:
Assigning User Logon and Logoff Scripts

Author Comment

ID: 40199454
I linked the GPO to the root of the domain and it started working.

When I un-link it from the root of the domain and link it to the OU that contains the user for which I want the script to run, it doesn't run.

Author Comment

ID: 40199462
Here is an Excerpt from the output of the command GPRESULT /R from the command line of one of the users in the OU showing the LogonScriptTest GPO has been applied.

Applied Group Policy Objects
     Default Domain Policy
     Local Group Policy
LVL 29

Expert Comment

ID: 40293194
It seems there may be an override that prevents your GPO from working, you may want to block inheritance on that OU and try again.

Author Closing Comment

ID: 40329214
I kept reading the documentation and while I couldn't spot anything specific wrong, I just kept trying and it finally started to work. I must have been doing something slightly wrong and continued trial and error with information at the provided links must have finally set me straight.

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question