Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of users' Windows XP machines within an IP range that are part of Windows 2003 AD. The names, unfortunately, don't have anything to do with the user names. Anyone know how I might script getting a username to machine name mapping?

My Domain admin account is a local admin on all ( or almost all) the boxes. So I might be able to query each box ( There is only ~40). I am open to ideas that will get me partial solutions. For example, if I only get this for 80% of the boxes, or if it is just that last person who logged in.

I am happy to script this from Linux if that is possible.

share|improve this question
up vote 3 down vote accepted

So your users don't ever move between computers, eh?

Devices / systems like Barracuda filtering appliances or WebSense handle this by running software on domain controller computers to monitor logons and build a database of logged-on users that gets updated in realtime.

I suppose you could use the PsLoggedOn SysInternals utility, but you're not going to be running that on a Linux machine.


Assuming list of computer names in "computers.txt" and "PsLoggedOn.Exe" in the path:

@echo off
for /F %%i in (computers.txt) do (
  call :do_check %%i

goto end

for /F "usebackq delims= " %%i in (`psloggedon \\%1 -x -l ^| find /v "NT AUTHORITY" ^| find /v "Users logged on locally"`) do echo %1,%%i


Send the output of that script to a file and you should get output of:


You can receive multiple responses per-computer, what w/ Windows being multi-user and all.

share|improve this answer
Doesn't have to be Linux. They do move around a little, but I am likely to know most of them if I see them lined up. Then I can go around and look at the left overs :-) – Kyle Brandt Aug 25 '09 at 17:49
Oh perfect, going to try that, thanks for the Windows Scripting Spoon Feeding :-) – Kyle Brandt Aug 25 '09 at 18:20

As you're using an active directory domain, you could use a logon script to do it but with only 40 machines it might just be quicker to go round to them and do it manually but look at the hostname command and %username% variable

I would question the need to do it at all though as most times it is advantageous to disassociate a computer from a user and by using roaming profiles, redirected folders and Group Policy, you should be able to do this fairly simply. I tend to use BGInfo (free from sysinternals) to display the computer name on the desktop wallpaper so that users can report their computer name to the support desk if necessary during the course of a support call.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.