Powershell Logon Script Failing

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
spencerturbineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

becraigCommented:
Is the GPO configured at:
Computer Configuration/Windows Settings/Scripts/Startup
0
spencerturbineAuthor Commented:
No, this is a logon script, not a startup script.
0
becraigCommented:
Is this the only script ?

Or are there others that run, but just not this one  ?
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

spencerturbineAuthor Commented:
This is the only script.
0
becraigCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
spencerturbineAuthor Commented:
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
spencerturbineAuthor Commented:
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
becraigCommented:
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
spencerturbineAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.