Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a text file of every machine in our Windows Active Directory domain, and I would like to determine the currently logged in user (if any) and operating system of each machine using WMIC:

WMIC /NODE:<machine_name> OS GET caption

Does anyone know how this could be scripted to read my list of computers from a text file and execute the two WMIC commands for each and output the results in the format:

ComputerName, OperatingSystem, CurrentUserName
share|improve this question
Why do you need to use WMIC? I would use powershell – Jim B Nov 24 '09 at 4:40

1 Answer 1

up vote 5 down vote accepted

I wouldn't recomend using wmic for this, (although you could use a for lop in a batch file) , as it's far easier in powershell (which is the way the question is tagged). Off the top of my head I'd do this:

$File = "Machines.txt"
get-Content $File | foreach-object { 
$uname = (get-wmiobject win32_computersystem -computername $_).username ;
$os = (get-wmiobject win32_operatingsystem -computername $_).caption ;
"$_ $os $uname"

the only bits that aren't fairly obvious is that on line 6 simply typing the names of variables outputs them to the console and the special variable "$_" means "This current object"

share|improve this answer
Thanks looks would one output this to a csv file? – tbone Nov 24 '09 at 15:32
"$_ $os" +", " + "$uname" | out-File "C:\!Powershell\export.csv" -append; – tbone Nov 24 '09 at 16:49

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.