Capture the actual user during impersonation

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
raghu_g
Posts: 1
Joined: Mon Jul 15, 2019 2:32 am

Capture the actual user during impersonation

Post by raghu_g »

Hi!

I'm on Powershell Studio 2019 and I'm trying to figure out how to capture the actual username when they run an executable which is impersonating (or running as) another user. Does anyone have any tips on how I could capture this information inside the actual script? I see that there are two consoles launching when the script is executed. I can guess the first is just a "run as" wrapper launching my actual executable. Maybe the first console could capture the actual environment variable of the username and pass it to second console?

To clarify; the situation is that User A runs an EXE which I have configured to execute by impersonating user B. In my code, $([Environment]::UserName) returns the username of user B. I was wondering what I could to capture username of User A within my code.

Update : I was able to solve this but it won't let me post my snippet. It somehow thinks I am posting an external link.