hi,
You can use Register-ScheduledTask to have a try. You can try scheduling a task on your local machine for whenever a user login session starts. Here's the script to do that:
$action = New-ScheduledTaskAction -Execute "Cmd"
$trigger = New-ScheduledTaskTrigger -AtLogon
Register-ScheduledTask StartAtUserLogin -Action $action -Trigger $trigger -Description "Schedule Task at User Login" -RunLevel Highest
You can specify your required action in the $action parameter. Once this code is working fine for your local machine, you can just put this script inside a Scriptblock and call this script using Invoke-Command cmdlet:
Invoke-Command -ComputerName $myserver -Credential $cred -Scriptblock { #place above script here }
--please don't forget to Accept as answer if the reply is helpful--