nav2567
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You .bat code works for me. Do you mean c:\names.txt only has the last one? Try changing > to >>
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
.....
Name
---------------
Smith, John
Name
-------------
Brown, Mary
Can you modify the script to get rid of the repeated titles?
Name
-----------
Smith, John
Brown, Mary
.....
ASKER
NewVillageIT, for some reason, my script only displays the last SAMID's name.
ASKER
Will, can you please modify your script to display just the following:
samid Names
jsmith Smith, John
mbrown brown, Mary
........
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
ASKER
NewVillageIT, the names.txt file is blank after running your script.
Nav.. What happens to names.txt if you remove:
| find ","
| 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
}
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
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.
Will.