Find Computer name through username

If you want to search computer name of a system on network through its username what you have to do is copy this script and paste it on notepad save it with any name but extension should be .bat or .cmd forexample: "username.cmd"


@ECHO OFF

:GETUSERNAME
ECHO.
SET UName=
SET /P UName=Enter Username for %USERDOMAIN%:
IF [%UName%]==[] (
ECHO Please provide username.
CALL :GETUSERNAME)

NET USER "%UName%" /DOMAIN 2>NUL>NUL
IF ERRORLEVEL 1 (
ECHO Username not found in Active Directory.
GOTO :GETUSERNAME)

ECHO Please wait... &ECHO.
FOR /F "delims=\\ " %%c IN ('NET VIEW ^|FIND "\\"') DO (
PING -n 1 -l 10 -w 100 %%c |FIND /I "TTL" >NUL
IF NOT ERRORLEVEL 1 (
REG QUERY "\\%%c\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName |FIND /I "%UName%" >NUL
IF NOT ERRORLEVEL 1 ECHO %UName% is logged onto %%c))

ECHO.
PAUSE
FOR /L %%v IN (1,1,24) DO ECHO.
PAUSE


:ENDSCRIPT
EXIT