June 25th, 2013

PowerTip: Use a .NET Framework Class in PowerShell to Get User Info

Doctor Scripto
Scripter

Summary: Use a .NET Framework class in Windows PowerShell to get user name and domain name information.

Hey, Scripting Guy! Question How can I use a .NET Framework class in Windows PowerShell to get a user name and domain in the format userdomain\username, without building a string?

Hey, Scripting Guy! Answer Use the Name property from the GetCurrent static method of the WindowsIdentity .NET Framework class:

[System.Security.Principal.WindowsIdentity]::GetCurrent().Name

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.