Created
April 10, 2017 19:42
-
-
Save vijayjt/01ce67a7e8a07a22bf11c722c8bf4738 to your computer and use it in GitHub Desktop.
How to search AD using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = 'aduser' | |
$password = 'replaceWithPassword' | |
$DomainControllerIpAddress = '192.168.0.21' | |
$LdapDn = 'dc=acme,dc=local' | |
$dn = New-Object System.DirectoryServices.DirectoryEntry ("LDAP://$($DomainControllerIpAddress):389/$LdapDn",$username,$password) | |
# Here look for a user | |
$ds = new-object System.DirectoryServices.DirectorySearcher($dn) | |
$ds.filter = "((userPrincipalName=*))" | |
$ds.SearchScope = "subtree" | |
$ds.PropertiesToLoad.Add("distinguishedName") | |
$ds.PropertiesToLoad.Add("sAMAccountName") | |
$ds.PropertiesToLoad.Add("lastLogon") | |
$ds.PropertiesToLoad.Add("telephoneNumber") | |
$ds.PropertiesToLoad.Add("memberOf") | |
$ds.PropertiesToLoad.Add("distinguishedname") | |
$ds.PropertiesToLoad.Add("otherHomePhone"); | |
$ds.FindAll() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment