Link to home
Start Free TrialLog in
Avatar of _-W-_
_-W-_Flag for United States of America

asked on

PERL - Search Active Directory for specific username

I am trying to write a script in perl to search active directory for a certain username.

I wrote it in powershell, as an example:
$first = "Tom"
$last = "Themachine"
$firstchar = $first.substring(0,1)
echo "$last$firstchar"
$account1 = "$last$firstchar"
$struser = "$account1"
 $dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
 $search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(sAMAccountName=$struser)"
$result = $search.FindAll()
 if ($result -ne $null){Write-Host $struser " Exists"}
else {
Write-Host $struser "does not exist" }

Open in new window

This returns "ThemachineT does not exist" ..because the username ThemachineT does not exists in my domain
I am looking for good script examples, not one word hints. I need good examples I can work with. Thanks! I will reward maximum points!
Avatar of Glen Knight
Glen Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

What provider are you using?

I am by no means a scripting or programming guru but it doesn't look like you have specified one?

See here: http://support.microsoft.com/kb/187529

and an example script here: http://www.roth.net/blog/index.php/2006/04/27/how-do-you-query-active-directory-with-perl/
ASKER CERTIFIED SOLUTION
Avatar of jeromee
jeromee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial