Get User Ad Properties using Windows PowerShell

Instead of using AD Powershell, below script can be used  to get any user details from On-Prem Active Directory any vanilla powershell console.

$root = [ADSI]”
$SAMName = ‘username’
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)
$searcher.filter = “(&(objectClass=user)(sAMAccountName= $SAMName))”
$user = $searcher.findall()
$user.Properties

This can be extended for multiple users if needed.

Add the below line to get the list of properties

$user.Properties.PropertyNames

To get the count

$user.Properties.PropertyNames.Count

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s