output computer, AD User
Posted: 23 Apr 2021 12:20
I'm trying to have a batch file read a list of computers from a text file and do a query to the computer for the active username and then do a dsquery to get the display name for the associated username. Then output the results of COMPUTERNAME and the DISPLAYNAME it finds in AD for the user.
Code: Select all
@Echo OFF
For /F "Usebackq Delims=" %%# in (
"C:\users\myuser\desktop\List.txt"
) do (
for /F "tokens=1" %%f in (
'query user /server:%%# ^| find "Active"'
) do (
dsquery user -samid %%f|dsget user -display >> C:\output.txt
)
)