I have a text file containing samids:
XXXXXXX
YYYYYYY
ZZZZZZZ
For each one I need to read it quering AD with this:
dsquery user
Use Get-ADUser
from the ActiveDirectory
PowerShell module instead of the ds tools:
Import-Module ActiveDirectory
Get-Content 'C:\path\to\input.txt' |
Get-ADUser -SearchBase 'DC=example,DC=org' -Property mail |
select -Expand mail | Out-File 'C:\path\to\output.txt'
Where DC=example,DC=org
is the distinguished name (DN) of your forest root domain.
For programmatically determining the DN of the forest root domain you could use this:
([ADSI]"LDAP://RootDSE").RootDomainNamingContext