![]() In this setup, the environment variable options return my account name, and the Windows access token option returns the service account name (which is what I wanted), and the logged in user option returns my account name.Īlso, if you want to compare the options yourself, here is a script you can use to run a script as another user. Because of a limitation of the way I'm running the PowerShell script from C#, the PowerShell instance uses my user account's environment variables, even though it is run as the service account user. The C# application is run with my user account, and it runs the PowerShell script as a service account. I've had to use Seemann's Windows access token approach in a PowerShell script that I was running from a C# application with impersonation. In short, the environment variable option is more succinct, and the Windows access token option is more dependable. ![]() is the most secure answer, because $env:USERNAME can be altered by the user, but this will not be fooled by doing that.
0 Comments
Leave a Reply. |