JSI Tip 8950. How can I generate a CSV file of Computer Name and User?

Using the net view command and Psloggedon freeware, I have scripted ComputerUserCSV.bat to create a .CSV file of computer names and logged on user names in a domain.

The syntax for using ComputerUserCSV.bat is:

ComputerUserCSV FileName

Where FileName is the name of the file that will contain "NetBIOS computer name","user SAMID", like:

ComputerUserCSV.bat contains:
@echo off
if \{%1\}==\{\} @echo Syntax: ComputerUserCSV FileName&goto :EOF
set file=%1
if exist %file% del /q %file%
set fnd1=Find /i "%USERDOMAIN%\"
set fnd2=Find /i /v "Error:"
set fnd3=Find /i /v "Unknown"
set fnd4=Find "\\"
for /f "Tokens=1" %%c in ('net view /domain:%USERDOMAIN%^|%fnd4%') do (
 set computer=%%c
 for /f "Tokens=*" %%u in ('psloggedon -l -x !computer!^|%fnd1%^|%fnd2%^|%fnd3%') do (
 set user=%%u
 call set user=!user:%USERDOMAIN%\=!
 @echo "!computer:~2!","!user!">>%file%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.