_-W-_
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:
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!
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" }
This returns "ThemachineT does not exist" ..because the username ThemachineT does not exists in my domainI am looking for good script examples, not one word hints. I need good examples I can work with. Thanks! I will reward maximum points!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/