Login | |
|
 |
RE: Active Directory Lookup - 12/5/2007 3:07:14 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 261
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
Here's one way you could handle this: $Searcher = New-Object DirectoryServices.DirectorySearcher $Searcher.Searchroot ="LDAP://DC=company,DC=local" get-content sams.txt | % { write $_ $searcher.filter = "(&(objectClass=user)(sAMAccountName= $_))" $searcher.FindOne().Properties.mail } Because you are filtering on the Samaccountname you should only get one match so you only need to find the first match. If you can use the free Quest AD cmdlets this can be done even easier: cat sams.txt | % {get-qaduser $_ | select dn,mail}
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
|
|
| |
|
|
|
 |
RE: Active Directory Lookup - 12/5/2007 10:12:01 PM
|
|
 |
|
| |
SAPIENScripter
Posts: 261
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
Save your results to a variable, then you can use the variable to send output to a file and do whatever else you want. $Searcher = New-Object DirectoryServices.DirectorySearcher $Searcher.Searchroot ="LDAP://DC=company,DC=local" get-content sams.txt | % { write $_ $searcher.filter = "(&(objectClass=user)(sAMAccountName= $_))" $results+=$searcher.FindOne().Properties.mail } The variable $results can now be piped to Out-file and you can use it for other things as well.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
|
|
| |
|
|
|
|
|