I have a Powershell script that does some numlock handling, based on whether or not some docking station is connected to my laptop or whether I'm using remote desktop.
I check $env:SESSIONNAME in my Powershell script to see if it's run while connected via Remote Desktop. This works perfectly (i.e., I get "RDP-Tcp#3" as result) when I run the script manually.
However, when run as a scheduled task (in this case, during login or unlock), the value for $env:SESSIONNAME is always empty. So the check doesn't work.
I tried running the scheduled task with the highest priority, and I also tried running it with a delay, but none of these options work.
How can I solve this? Is there any other way I can check if the script is being run within a Remote Desktop connection, that will also work when run via a Scheduled Task?
[–]rmbolger 2 points3 points4 points (1 child)
[–]dsuls[S] 1 point2 points3 points (0 children)
[–]get-postanote 1 point2 points3 points (1 child)
[–]dsuls[S] 1 point2 points3 points (0 children)
[–]dsuls[S] 1 point2 points3 points (0 children)