PowerShell One Liner for Directory Lookup

PowerShell

Upon request from one of my coworkers, a one-liner for DN from an AD account name.

$a=read-host; $s=New-Object
directoryservices.directorysearcher(”LDAP://dc=yerdomainhere”);
$s.filter=”(sAMAccountName=$a)”; $s.findone().path

Yeah, sad use of the semicolon I know, but it’s a 2 minute job. :)

No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>