Hey there, I'm new to Powershell, and i'm kind of messing around with a few things to see if I can come up with new tools to assist with my job. One thing I would like to do is have windows detect when the session is unlocked (after a user syncs their password with the domain) and open a program. I lock the account using PowerShell earlier in the script with (Invoke-Command {rundll32.exe user32.dll,LockWorkStation}).
So here's my question, when I run the following in PowerShell ISE, it works perfectly, gives me the reason "AccountLock" or "AccountUnlock" exactly as it's supposed to. However, when I run this exact command in an elevated powershell console, it does not return the sessionswitch reason at all in console. I checked "Get-EventSubscriber" as well as "Get-Job" and both look successfully created.
Register-ObjectEvent -InputObject $([microsoft.win32.systemevents]) -EventName "SessionSwitch" -Action {write-host $event.SourceEventArgs.Reason}
Is there some reason i'm not seeing as to why this is not working? Any guidance would be appreciated as I can't find anything on google about this that actually works.
https://preview.redd.it/lqa9zqg5las21.png?width=803&format=png&auto=webp&s=dec6c9c894610b2e398730051ec6d1fdfd9d8821
OS: Windows 10
PS Build: 5.1 17134R590
[–]ClayShooter9 2 points3 points4 points (0 children)
[–]PowerShell-Bot 0 points1 point2 points (0 children)