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"}


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

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 web sites. He blogs at LinuxWays.

Leave a Reply

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