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

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

  • Comments 5
  • Likes

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • This is actually a pretty nice tip!

    How do one come to know all(or the cool ones) the features of the dotNet framework classes?

  • Great tip. Explain why the .token changes.

  • @ mockmyb

    There are manyu kinds of tokens.  There are token gifts and token players as well as subway and bus tokens.

    IBM has invented a computer token.  Her eis the explanation for it:  pic.dhe.ibm.com/.../index.jsp

  • Here is the explanation for the Microsoft implementation of the access 'token' for the users current process context:

    msdn.microsoft.com/.../aa374909(v=vs.85).aspx

  • Excellent Post. Also visit www.msnetframework.com/framework.php