Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a GPO that is linked to an OU containing computers. Loopback processing is activated an set to merge. Within the user part of the GPO i have a powershell script defined that basically checks if its running inside a remode desktop session (if ($env:SESSIONNAME -ne 'Console')) and then tries to set an environment variable based on a modification of $env:CLIENTNAME.

However the script seems not to work as at the time of execution there is no $env:CLIENTNAME. How can i fix this?

I have already tried to enable and disable "Run logon scripts synchronously". If i enable it - no luck, which seems logical. When set to "Not configured" the above mentioned happens. Thanks for your input.

[EDIT]

When I invoke the script via "User Configuration => Policies => Administrative Templates => System => Logon => Run these programs at user logon" it seems to work. However not for every user and with a random latency.

Is there another way I can use powershell to query for %CLIENTNAME%? Like asking the remote desktop servies for logged in users... can you see where i am pointing at?

share|improve this question

1 Answer 1

This link here helped me to solve my problem:

http://rcmtech.wordpress.com/2011/06/09/how-to-get-clientname-within-logon-script-on-server-2008-r2-xenapp-6/

Now I am parsing the output of qwinsta and read the clientname from the registry which is earlier available then the var %CLIENTNAME%

Function Get-ClientName 
{
    $session = qwinsta $env:USERNAME
    $sessionId = $session[1].subString(39,9).Trim()

    return (Get-ItemProperty "HKCU:\Volatile Environment\${sessionId}\" -Name CLIENTNAME).CLIENTNAME
}

Then I am able to load my script from "User Configuration => Policies => Windows Settings => Scripts => Logon ..."

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.