≡ Menu

Find the SID of current logged on user using PowerShell

One of the things I like with PowerShell is its ability to use DotNet classes and methods. In this article we will such approach to find out what is the SID of current logged on user account using PowerShell.

DotNet assembly System.DirectoryServices.AccountManagement has a class called UserPrincipal which gives a simple way to get SID of current logged user. There are several other ways to do it but I found this is easiest of all.

Let see how to do this. First we need to add the System.DirectoryServices.AccountManagement assembly to PowerShell session. You can do it by Add-Type cmdlet.

Add-Type -AssemblyName System.DirectoryServices.AccountManagement

Once the assembly added, you can use below one-liner to query the Current User details and one of the property is SID.


Below screen shows the list of properties that this class provides.

current sid

Putting all these together, I made a quick PowerShell function that returns the SID of current logged on user.

function Get-CurrentUserSID {            
Add-Type -AssemblyName System.DirectoryServices.AccountManagement            
return ([System.DirectoryServices.AccountManagement.UserPrincipal]::Current).SID.Value            

You can import this function into your PowerShell window and use it. Let me know if you got any questions.

{ 3 comments… add one }
  • Dennis February 3, 2017, 8:23 pm

    Thx 🙂

  • Marc Jolley December 5, 2017, 5:55 pm

    This only works if you run the script as the currently logged in user, as it returns the SID of the account running the script. No use if you have to run elevated PowerShell prompts as a privileged admin if you’re trying to return the SID of the user logged into Windows.

    • Wintel Rocks December 29, 2017, 6:55 pm

      Do you mean by performing runas? If you run this from a shell that is started under another login shows that login only. Not the interactively logged on user.

Leave a Comment