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.
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?