0

I am trying to create a remote, WMI query script that will query a bunch of machines and tell me the MemoryChip configuration information. This way, we can find out what machines physically have 1 chip or 2 chips and how big each one is and find out who has a 1x4GB configuration and get them upgraded. The base I am running is: wmic /node:"[ComputerName]" MEMORYCHIP get BankLabel,DeviceLocator,Capacity,Tag > memory.txt

The problem is that this just kicks out the following, which provides no ability to reference the computer being queried: BankLabel Capacity DeviceLocator Tag
4294967296 DIMM A Physical Memory 0
4294967296 DIMM B Physical Memory 1

You run this 50x, and there's not a quick way to find out which machine has what. What I am trying to do is have the script Echo the "ComputerName" to the line preceding the text or append it at the next line. All of my efforts to do this have not produced viable results, so I am hoping at least one person who still uses batch (for things, quite frankly, I should learn powershell to execute) can help me with this.

6
  • What are you passing to /node - a list of machine IDs or a single ID?
    – Karan
    Jun 12, 2015 at 16:03
  • Right now, it is 1 machine per line. So each time we query a new machine, we start a new WMIC line. TL;DR - One machine per /Node switch Jun 12, 2015 at 16:53
  • Ok, so why not echo each machine ID to the text file before redirecting WMIC's output to the same file?
    – Karan
    Jun 12, 2015 at 16:57
  • @Karan I tried that. echo ... > file followed by wmic ... >> file sticks a load of NULs in file. Example "[ComputerName] ÿþB a n k L a b e l ", etc where the spaces are NULs. Hence my answer using wmic twice.
    – DavidPostill
    Jun 12, 2015 at 17:03
  • echo and wmic together redirecting to the same file seems to be a no no. Something to do with character sets maybe?
    – DavidPostill
    Jun 12, 2015 at 17:04

2 Answers 2

2

What I am trying to do is have the script echo the "ComputerName"

Try the following:

wmic /node:"[ComputerName]" OS get csname > memory.txt
wmic /node:"[ComputerName]" MEMORYCHIP get BankLabel,DeviceLocator,Capacity,Tag >> memory.txt

Output here (not including the /node option as I can't test it):

CSName
HAL
BankLabel  Capacity    DeviceLocator  Tag
Bank 0     4294967296  SODIMM1        Physical Memory 0

Where HAL is my computer name.

3
  • 1
    the "csname" works at getting the current machine's computer name, but I'm using the "/node:" switch to do a remote computer. So basically, if I enter the "wmic OS get csname" above each line, it gives the same output each time it is run. Perhaps if I use the "/node" with the "WMIC OS" I'll get the remote machine as well... Jun 12, 2015 at 17:25
  • Did the remote csname work as expected? If so I will update my answer.
    – DavidPostill
    Jun 12, 2015 at 17:34
  • So typing the following produces the closest to my desired result as I expect to get from batch: wmic /node:"[ComputerName]" OS get csname > memory.txt inline code in backticks wmic /node:"ComputerName" MemoryChip get BankLabel, Capacity, MemoryType, TypeDetail, Speed >> memory.txt Jun 12, 2015 at 17:34
1

Just use something like this:

@echo off
echo "ComputerName" >> Memory.txt
wmic /append:Memory.txt /node:"ComputerName" MemoryChip get BankLabel,DeviceLocator,Capacity,Tag
1
  • Sneaky way to get around the echo and wmic redirection problem. I will remember this one ;)
    – DavidPostill
    Jun 12, 2015 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .