WMIC invalid global switch – solved

Last Updated on October 12, 2017 by Dave Farquhar

I use WMIC a lot to gather data in my job. Querying computers that have dashes (a.k.a. the minus sign, the “-” character) in the names cause an error message that says “invalid global switch.” Microsoft operating systems use the dash as a reserved character to indicate command options. Here’s how to get rid of the WMIC invalid global switch problem.

Fixing WMIC invalid global switch

WMIC invalid global switch
WMIC makes managing networks of computers easier. Here’s how to fix the WMIC invalid global switch error.

The answer is to put the computer name in quotes.

This command won’t work:

wmic /node:dave-pc os get name

But this simple adjustment to the command, adding merely two characters, works just fine:

wmic /node:"dave-pc" os get name

Substitute the computer name (or your environment variable, if you’re doing a for loop in a batch file) for “dave-pc,” and you’ll be off to the races.

Using quotes when you don’t need them is OK. They won’t hurt anything.

Uses for WMIC

Many companies do put dashes in computer names. That means this adjustment makes it much easier to get information from WMIC on corporate networks. WMIC will get you a host of information very quickly, which is extremely useful to system administrators and security analysts. But when the picture is incomplete due to the use of dashes, obviously the information is less valuable.

When I was working for a large company that had done several mergers in its history, I frequently fielded questions about whether certain makes or models of computers were more reliable than others. I suppose that isn’t a surprising outcome when Dell, HP, and Lenovo shops merge with each other. Everyone has their favorite and of course it isn’t their favorite that’s causing the issue.

Given a long list of problematic PCs, I was able to craft a batch file using WMIC queries in a matter of minutes that proved there was no significant difference in reliability between makes of PCs, or, at least, those three particular makes of PCs. The percentages of each brand in the sample population turned out to be nearly identical to the percentages in the population as a whole. I also found the age of the PC was a less reliable indicator of problems than I expected. WMIC is incredible.

You fixed the WMIC invalid global switch message. Now go get some great data of your own with WMIC.

I have some more Windows scripting tips if you’re interested.

If you found this post informative or helpful, please share it!
%d bloggers like this: