Skip to content

Instantly share code, notes, and snippets.

@kasuken
Created September 11, 2020 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasuken/31805c24bb4eee84b700798c1ea2ea9c to your computer and use it in GitHub Desktop.
Save kasuken/31805c24bb4eee84b700798c1ea2ea9c to your computer and use it in GitHub Desktop.
Retrieve UPN from .NET Core
var procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c whoami /upn");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
var email = result.Trim();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment