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;"
$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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

Or are there others that run, but just not this one  ?
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

spencerturbineAuthor Commented:
This is the only script.
Here is some good reading to make sure you have it setup correctly:

See section:
Assigning User Logon and Logoff Scripts

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.
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
     Local Group Policy
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.
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.
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

From novice to tech pro — start learning today.