Skip to content

Instantly share code, notes, and snippets.

@ScriptingPro
Last active February 16, 2024 00:40
Show Gist options
  • Save ScriptingPro/f8adffbbeef35347c6e5a5644d503633 to your computer and use it in GitHub Desktop.
Save ScriptingPro/f8adffbbeef35347c6e5a5644d503633 to your computer and use it in GitHub Desktop.
# directoryentry (connect to specific dc:port)
$de = ([ADSI]"LDAP://$($ADDomainController.HostName):$($ADDomainController.LdapPort)")
# directorysearcher
$ds = New-Object System.DirectoryServices.DirectorySearcher($de,"(objectclass=user)")
$ds.PageSize=1000
# invoke
$ds.FindAll() | %{"do stuff with $_"}
$thisuser = $ds.FindOne()
$thisuserde = $thisuser.GetDirectoryEntry()
# Invoke get property
($([ADSI]"LDAP://$($adsiref.distinguishedName)").Invoke("get","name"))
# example get pwdlastset from user directoryentry
[datetime]::FromFileTime($thisuserde.ConvertLargeIntegerToInt64($thisuserde.pwdLastSet[0]))
# example get pwdlastset from user searchresult
[datetime]::FromFileTime($($thisuser.Properties["pwdlastset"]))
# List RootDSE DirectoryEntry properties
[ADSI]"LDAP://RootDSE" | fl *
# Get configurationNamingContext
([ADSI]"LDAP://RootDSE").configurationNamingContext
([ADSI]"LDAP://RootDSE").get("configurationNamingContext")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment