?
Solved

Powershell Logon Script Failing

Posted on 2014-07-15
9
Medium Priority
?
249 Views
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;"
$conn.open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.connection = $conn
$cmd.commandtext = "INSERT INTO tbl_Logon(username) VALUES('{0}')" -f $env:username
$cmd.executenonquery()
$conn.close()

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?

Thanks
0
Comment
Question by:spencerturbine
  • 5
  • 4
9 Comments
 
LVL 29

Expert Comment

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

Author Comment

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

Expert Comment

by:becraig
ID: 40197717
Is this the only script ?

Or are there others that run, but just not this one  ?
0
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

by:spencerturbine
ID: 40197727
This is the only script.
0
 
LVL 29

Accepted Solution

by:
becraig earned 2000 total points
ID: 40197756
Here is some good reading to make sure you have it setup correctly:
http://technet.microsoft.com/en-us/magazine/dd630947.aspx

See section:
Assigning User Logon and Logoff Scripts
0
 

Author Comment

by:spencerturbine
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.
0
 

Author Comment

by:spencerturbine
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
     LogonScriptTest
     Local Group Policy
0
 
LVL 29

Expert Comment

by:becraig
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.
0
 

Author Closing Comment

by:spencerturbine
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.
0

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