I've created a script the detects a users session type (RDP or Console) and it works fine running simply be clicking the script but when deploying using GPO from 'User Configuration\Windows Settings\Security Settings\Scripts\Logon' it doesn't appear to be able to get the session type.

I've tried the following

$sessionname = ExpandEnvironmentVars(%sessionname%)

and

@LOGONMODE

Can anyone tell me why these don't appear to work when used on GPO but do from manually running.

I think it's something to do with the way GPO executes scripts run as say system but this is only a guess.

Does any have any other solutions to find out if the logging on user is running in an RDP session or Console?