Username to Windows Machine Name Mapping

Posted on

Username to Windows Machine Name Mapping – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about windows, active-directory, , , .

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.

Solution :

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.

Edit:

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

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

:end

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

computername,username
...

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *