Check if a user or group exists in AD using PowerShell
Easily check if user or group exists with PowerShell
John Savill
January 25, 2017
1 Min Read
Q. How can I easily check if a user or group exists in AD using PowerShell?
A. The easiest way to check for a user or group in AD using PowerShell would be the following. Note it gets the object based on a simple filter and if the resulting object is null it means it was not found.
$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"}
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like