spencerturbine
asked on
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.SqlC onnection
$conn.ConnectionString = "Data Source=MYSERVER;Initial Catalog=data;Integrated Security=SSPI;"
$conn.open()
$cmd = New-Object System.Data.SqlClient.SqlC ommand
$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\m yscript.ps 1
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
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.SqlC
$conn.ConnectionString = "Data Source=MYSERVER;Initial Catalog=data;Integrated Security=SSPI;"
$conn.open()
$cmd = New-Object System.Data.SqlClient.SqlC
$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\m
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
ASKER
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 ?
Or are there others that run, but just not this one ?
ASKER
This is the only script.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
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
Applied Group Policy Objects
--------------------------
Default Domain Policy
LogonScriptTest
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.
ASKER
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.
Computer Configuration/Windows Settings/Scripts/Startup