Find If a User Exists in Azure AD Using PowerShell

In this blog post, we will be discussing Azure Active Directory and Azure AD PowerShell. Azure AD is a service provided by Microsoft Azure. It allows you to create a directory of users on the cloud that can connect from any device or location. We will go over how you can use PowerShell to find if a user exists in Azure AD.

This post will focus on how to check if a user exists in the Azure Active Directory using the AzureAD PowerShell module. The code that you will search for is an Azure AD user display name.

If the user exists, the script will display the name of the user. In the example, I’m using a variable called $myuser to store the name of the user. You can either pass the value to the script or use other methods.

To base the search based on UPN, write the UPN in the $myuser var and change the $user.displayname to $user.UserPrincipalName

import-Module azureadpreview
$myuser = "Mike Smith"
$users = Get-AzureADUser 
foreach($user in $users)
 if($user.displayname -like $myuser)
       "User:"  + " " + $myuser + " " + "exist"


About Azure AD PowerShell

Azure AD PowerShell is a module that allows you to manage Azure Active Directory. Azure AD PowerShell is a set of cmdlets that allow you to connect to Azure AD and manage users, groups, and licenses. Azure AD PowerShell can be installed on Windows 10, 11 and Windows Server. You must be a global administrator in Azure AD to use Azure AD PowerShell.

To install Azure AD PowerShell, open PowerShell as an administrator and run the following command:

Install-Module AzureAD

After Azure AD PowerShell is installed, you can connect to Azure AD by running the following command:


Success! You're on the list.