fbpx
Active Directory & Office 365 Reporting Tool

Are you trying to find the sAMAccountName of a user in Active Directory? As a SysAdmin, you may come across situations where you need to locate the sAMAccountName of a user in AD

Fortunately, there are multiple tools available to you to perform this task, and in this article, I’ll share five of them. 

Specifically, I show you how to find a user’s sAMAccountName using Active Directory Users and Computers (ADUC). You’ll also learn how to perform tasks with Active Directory Administrative Center (ADAC) and ADSIEdit. 

Finally, if you love CMD and PowerShell, there are two sections about how to find sAMAccountName with these command line tools.

Let’s do this!

How to Locate a User's sAMAccountName with Active Directory Users and Computers (ADUC)

ADUC is the go to tool for most SysAdmins. Also one of the common tools you use to find a user’s AD logon name (also known as sAMAccountName).

To use ADUC to find the sAMAccountName for a user, follow the steps below:

1. While logged in to your AD server with Admin credentials, open Server Manager. Then, click Tools on the top right of Server Manager and select Active Directory Users and Computers.

2. When ADUC opens, navigate to the container the user is located. In my example (see the screenshot below), my user is located in the “Writers” OU. 

3. Right click the user and select Properties

3. When the user’s Properties opens, click the Account tab. The Account tab is next to the Address tab. 

4. Finally, the user’s Active Directory sAMAccountName is the “User logon name pre-Windows 2000.” I have highlighted my user’s SamAccountName in the screenshot below. 

Find User's sAMAccountName with Active Directory Administrative Center (ADAC)

Another tool you can use to find a user’s AD logon name is ADAC. 

Here are the steps to use Active Directory Administrative Center to perform this task

1. Log in to a Domain Controller with Admin credentials and open Server Manager. Then, click Tools on the top right of Server Manager and select Active Directory Administrative Center.

2. Then, when ADUC opens, click the AD container where the user is located. On the details pane, right click the user you want to get its sAMAccountName and select Properties. You may also access the users’ Properties by left clicking the user. Then, on the right pane, left click on Properties – see the second screenshot below. 

3. When the user’s Properties opens, the sAMAccountName is located at the Account tab (opens by default) – see my arrow pointing in the screenshot below. 

Find SamAccountName in Active Directory using InfraSOS Report Tool

Try us out for Free, Access to all features. – 200+ AD Report templates Available. Easily customise your own AD reports.

How to Get a User's AD sAMAccountName with ADSI Edit

Most Windows SysAdmins may be familiar with ADUC and ADAC, but most may not know about ADSI Edit (Active Directory Service Interfaces Editor).

ADSI Edit is a “hidden gem” that allows you to manipulate Active Directory objects in ways that ADUC and ADAC may not. 

Whether you’ve used ADSI Edit before or not, follow the steps below to use it to find a user’s SamAccountName.

1. As with the other two sections, to open ADSIEdit from Server Manager, click Tools; then select ADSI Edit 

If you open ADSI Edit for the first time, its interface will be blank. 

2. To connect ADSI Edit to your Active Directory Domain, right click ADSI Edit on the left pane. Then, select Connect to

3. When the Connection Settings window opens, click OK. This connects ADSI Edit to the Active Directory’s default naming context. 

4. To display the objects in AD, click the Default naming context. Then, to expand it, click the tiny forward pointing arrow on the top left of the Default naming context. Finally, click your domain name to display available objects on the right pane. 

5. Once your Active Directory objects display in ADSI Edit, locate the object container of the user you want to get its sAMAccountName and double click it. In this example, my user is located in the “Writers” OU. 

Next, right click the user and select Properties

5. Finally, locate sAMAccountName for the user in the CN attribute Properties of the user. 

Pro tip: Instead of scrolling through all the properties to locate sAMAccountName, you select any property, then type sam on your keyboard. 

How to Find a User's AD sAMAccountName with PowerShell or CMD

In this final session, you learn how to find the sAMAccountName of a user with Windows PowerShell or Command Prompt (CMD). The session is divided into two sub-sessions – the first for PowerShell and the second for CMD. 

Furthermore, in each session, I have examples of how to find the sAMAccountNames for one user or all users in an Organizational Unit (OU).

Find a User's AD sAMAccountName with Windows PowerShell

To display the sAMAccountName of a specific user, follow the steps below:

1. Follow the steps in the previous section to find the user’s distinguishedName (DN). Then, double click the DN and copy the Value

2. Next, search for PowerShell, right click Windows PowerShell, and select Run as Administrator

3. When Windows PowerShell opens, enter the command below and press the enter key on your keyboard to execute it. 

Replace the identity with the distinguishedName you copied in step 1. 

				
					Get-ADUser -Identity "CN=Anthony Raj,OU=Writers,DC=itechguides,DC=local" | Select-Object Name, sAMAccountName
				
			

The command displays the Name and sAMAccountName of the user – highlighted the sAMAccountName in the screenshot below. 

Alternatively, display the sAMAccountName of all users in an Active Directory container, for example, an OU. To perform this task, first, get the distinguishedName (DN) of the AD container using the steps in the third section of this guide.

Then, replace the SearchBase parameter in the command below with the DN of your AD container. 

				
					Get-ADUser -Filter * -SearchBase "OU=Writers,DC=itechguides,DC=local" | Select-Object Name, sAMAccountName

				
			

The above command displays the Name and sAMAccountName of all users in the “Writers” OU in my test Active Directory domain

Find a User's Active Directory sAMAccountName - Windows Command Prompt

1. Search cmd, then right click Windows Command Prompt and select Run as administrator

2. On Windows Command Prompt, copy and paste the command below. Then, to execute it, press the Enter key on your keyboard. 

Replace  “CN=Anthony Raj,OU=Writers,DC=itechguides,DC=local” with the distinguishedName of the user you want to need its sAMAccountName.

				
					dsget user "CN=Anthony Raj,OU=Writers,DC=itechguides,DC=local" -dn -samid
				
			

The screenshot below shows the sAMAccountNameThe dsget command displays sAMAccountName as samid. 

Just like with PowerShell, you also display the sAMAccountName of all users in an AD container – for instance, an OU. The command below displays the sAMAccountName (the samid column) of all users in the OU with DN, “CN=Anthony Raj,OU=Writers,DC=itechguides,DC=local”

Before you run the command, replace the DN with the DN of the AD object you’re querying. 

				
					dsquery user "OU=Writers,DC=itechguides,DC=local" -limit 0 | dsget user -samid -display
				
			

How to Find SamAccountName in Active Directory Conclusion

As shown in this article, Windows offers multiple methods to find the sAMAccountName of an Active Directory user. Specifically, you get an AD user’s sAMAccountName using ADUC and ADAC. 

In addition to those two tools, you can also perform this task with ADSI Edit. Finally, if you love working with commands, there are commands to perform the task with Windows PowerShell and Command Prompt

That is it. Thank you for reading, and I hope you found this guide helpful!

InfraSOS-AD-Tools

Try InfraSOS for FREE

Invite your team and explore InfraSOS features for free

Victor Ashiedu

Victor Ashiedu

Victor is an IT pro based in Manchester, UK. With over 22 years of experience managing Windows Server, Active Directory, and Powershell, and 7 years of expertise in Azure AD and Office 365, he's a seasoned expert in his field. When he's not working, he loves spending time with his family - a wife and a 5-year-old. Victor is passionate about helping businesses succeed in today's fast-changing tech landscape.

Leave a comment

Your email address will not be published. Required fields are marked *