X

How to Check if a User or Group Exists in AD using PowerShell

If you want to check the existence of any user or group in Windows Active Directory, use the following PowerShell script.

PowerShell: Check if AD User or Group Exists

Step 1. Open PowerShell with elevated privileges.

Step 2. Execute the following script:

$userobj = Get-ADUser -LDAPFilter "(SAMAccountName=$username)"

$vlanobj = Get-ADGroup -LDAPFilter "(SAMAccountName=$vlangroupname)"

if ($userobj -eq $null) {"User not valid"}
if ($vlanobj -eq $null) {"VLAN not valid"}

 

Karim Buzdar: About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various websites.
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings