Avatar of Siddharth S
Siddharth S
 asked on

Multiple wmic commands in a single batch file

Hi Guys,

Can anyone help me as to how I can store multiple wmic get commands into a single batch file.

The following commands are what I am looking to add in a single batch.

1) wmic os get csname
2) wmic cpu get name
3) wmic os get caption

Now I understand 1 & 3 can be seperated from commas but the Idea is to get wmic os & wmic cpu run in the same batch file and output it to a particular location say c:\hardware.

Thanks in advance.


EDIT: I did figure out how to do that in the meanwhile. Below is the code. However this is saving the output in the form of rows. How can I save the output in the form of columns. That is the computer_name should be in one column and its subsequent row should have the value. Similarly Name should be the next column and its subsequent row should be the model of the laptop etc.

Below is the code:
@echo off
if exist C:\dell\%computername%.csv del C:\dell\%computername%.csv
set outputfile="C:\dell\%computername%.csv"


hostname>>%outputfile%

wmic csproduct get name>>%outputfile%

wmic bios get serialnumber>>%outputfile%

wmic diskdrive get model>>%outputfile%

wmic path win32_physicalmedia get SerialNumber>>%outputfile%
goto :eof

Open in new window

Windows Batch

Avatar of undefined
Last Comment
Siddharth S

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Michael Pfister

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Michael Pfister

Ok, sorry forgot your first few lines:
@echo off
if exist C:\dell\%computername%.csv del C:\dell\%computername%.csv
set outputfile="C:\dell\%computername%.csv"
for /f "delims== tokens=2" %%i in ('wmic csproduct get name /value') do SET CSPRODUCT=%%i
for /f "delims== tokens=2" %%i in ('wmic bios get serialnumber /value') do SET SERIAL=%%i
for /f "delims== tokens=2" %%i in ('wmic diskdrive get model /value') do SET DISK=%%i
for /f "delims== tokens=2" %%i in ('wmic path win32_physicalmedia get SerialNumber /value') do SET PMSERIAL=%%i
echo Hostname,Model,Serial,Disk,DiskSerial>>%outputfile%
echo %CSPRODUCT%,%SERIAL%,%DISK%,%PMSERIAL%>>%outputfile%

Open in new window


And I can't check here what happens in case the computer has for example more than one harddisk. I'm pretty sure it will fail or deliver incomplete results.
Siddharth S

ASKER
Amazing. Thanks.. !! I will hold onto this for a day. I have a bit of modifications to do post which I will close the question. :)

In the meanwhile if I have any doubts in it, I will resume.

And yes, it is delivering no result when there are 2 Hard disks. But I dont think I need that bit.
Bill Prew

I'm trying something to try and get the disk (multiples) info as well, if you want to wait and see if I have success...

~bp
Your help has saved me hundreds of hours of internet surfing.
fblack61
Siddharth S

ASKER
Sure Bill. You helped me the last time as well :)

But I would ask you to wait on it as I will be modifying the code quite a bit to get the hardware info. We can try on it once I make changes to my code..
SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Siddharth S

ASKER
Thanks both. Awesome. We do not have systems where 2 disks are present so I am good for now.

Awesome help as ever.