I have a text file containing samids:
XXXXXXX YYYYYYY ZZZZZZZ
For each one I need to read it quering AD with this:
dsquery user
Finally, I managed to solve it this way proposed on the other post:
$a = Get-Content .\input.txt for ($i=0 ; $i -lt $a.Length; $i++){ dsquery user forestroot -samid $a[$i] | dsget user -email | Select-String '@' | select -Expand Line >> output.txt }
Thank you