Function Find-User { Param ($sam=$(throw "you must enter a sAMAccountname")) $searcher=New-Object DirectoryServices.DirectorySearcher $searcher.Filter="(&(objectcategory=person)(objectclass=user)(sAMAccountname=$sam))" $results=$searcher.FindOne() if ($results.path.length -gt 1) { write $results } else { write "Not Found" } } #example Find-User $env:username