Rich
Rich

Reputation: 21

WMIC Batch File

I am trying to use a .bat to get system info with WMIC. I want to create a folder in C:\ with the name of the computer, then have a few .txt files made within the folder with the info on I am seeking. This is what I have so far:

start cmd
cd C:\
md C:\%computername%_Software_Baseline
wmic 
/output:C:\%computername%_Software_Baseline\Installed_Software.txt product get name,version

This is where my first roadblock is. I get the message that the file name is invalid. The next few are the other .txt files I want to create in that folder as well (Once I can do the first I should be able to apply it to these as well).

/output:C:\%computername%_Software_Baseline\Computer_System_Information.txt computersystem get domain,manufacturer,model,name,totalphysicalmemory
/output:C:\%computername%_Software_Baseline\Disk_Drive_Information.txt diskdrive get model,size,manufacturer
/output:C:\%computername%_Software_Baseline\CPU_Information.txt cpu get architecture,currentclockspeed,description,extclock,l2chachesize,manufacturer,name
/output:C:\%computername%_Software_Baseline\BIOS_Information.txt BIOS get serial number,name,smbiosbiosversion,manufacturer
/output:C:\%computername%_Software_Baseline\OS_Information.txt OS get name,cdsversion,manufacturer,freephysicalmemory,buildnumber

I also want this to save everything to a folder on my network as well, but that can wait until I get the script going.

Upvotes: 2

Views: 1233

Answers (1)

JosefZ
JosefZ

Reputation: 30113

I can't understand why not to perform the task within current cmd instance omitting start cmd:

@ECHO OFF
SETLOCAL enableextensions

md "C:\%computername%_Software_Baseline"
wmic /output:"C:\%computername%_Software_Baseline\Installed_Software.txt" product get name,version

or using pushd - popd command pair:

@ECHO OFF
SETLOCAL enableextensions

md "C:\%computername%_Software_Baseline" 2>NUL

pushd "C:\%computername%_Software_Baseline"
wmic /output:"Installed_Software.txt" product get name,version
     rem further wmic commands here
popd

When a UNC path is specified, PUSHD will create a temporary drive map and will then use that new drive. The temporary drive letters are allocated in reverse alphabetical order, so if Z: is free it will be used first.

POPD will also remove any temporary drive maps created by PUSHD.

Upvotes: 1

Related Questions