Link to home
Start Free TrialLog in
Avatar of nav2567
nav2567Flag for United States of America

asked on

script to read a txt file of SAMID and display full user names.

Hello,

I need a command to read a txt file which contains a list of SAMID and out the full user names into another txt file.  

I have tried the following but it only displays the full user name of the last SAMID:

for /f %%i in (c:\samid.txt) do dsquery user -samid %%i |dsget user -fn -ln > c:\names.txt

Can someone advise what is missing?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada 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
You .bat code works for me. Do you mean c:\names.txt only has the last one? Try changing > to >>
Avatar of nav2567

ASKER

Fine.  I am getting the following display:

Name
---------------
Smith, John

Name
-------------
Brown, Mary

Can you modify the script to get rid of the repeated titles?

Name
-----------
Smith, John
Brown, Mary
.....
Avatar of nav2567

ASKER

NewVillageIT, for some reason, my script only displays the last SAMID's name.
Avatar of nav2567

ASKER

Will, can you please modify your script to display just the following:

samid           Names
jsmith           Smith, John
mbrown       brown, Mary
........
Maybe this...
for /f %%i in (c:\samid.txt) do dsquery user -samid %%i | dsget user -fn -ln | find "," >> c:\names.txt

Open in new window

Avatar of nav2567

ASKER

NewVillageIT, the names.txt file is blank after running your script.
Nav..  What happens to names.txt if you remove:

| find ","
import-module activedirectory
$UserList = get-content "c:\filename.txt"
ForEach ($User in $UserList) {
Get-ADUser -Identity $User | select samaccountname, Name | Out-file "c:\filename2.txt" -append
}

Open in new window


That does it.

Will.
for /f %%i in (c:\samid.txt) do dsquery user -samid %%i | dsget user -fn -ln | find /v "fn" >> c:\names.txt

Open in new window

Are you going to close this question? I have provided you the additional code required as requested. If you are having issues or is it not working as expected, please let me know.

Will.