Home > Articles

  • Print
  • + Share This
This chapter is from the book

Running wmic

wmic is a shell command similar to netsh, covered in Chapter 11, "Configuring Windows 7 with netsh." You can enter wmic from the command prompt to enter the wmic shell. The wmic shell prompt starts in the root\cli name space, from which you can then enter commands. For example, if you want to get detailed information on the computer, you can use the computersystem list full command:

C:\>wmic
wmic:root\cli>computersystem list full

You can also enter the full wmic command from the command prompt by preceding it with wmic. For example, the following command provides the same output as the previous command:

C:\>wmic computersystem list full

If you were writing this within WMI (not wmic), you would have to understand the query language, and the query would look something like this:

Select * from Win32_ComputerSystem

However, thanks to the wmic built-in aliases, you don't have to learn the query language to use wmic.

The wmic command includes several switches. Some of the more common switches are listed in the following table.

Switch

Description

/? [:brief | :full]
C:\>wmic /?
C:\>wmic /?:full
               

Shows the syntax of all global switches and aliases.

The default listing is brief, but you can also specify full to get a more verbose listing of help.

/node: remotecomputer wmic /node: remotecomputer command
C:\>wmic /node:win7pcg computersystem
C:\>wmic /node:win7pcg printer list brief
               

You can use the /node switch to retrieve information from any remote computers.

The first example retrieves information with the computersystem alias, and the second example uses the printer alias.

/user: username wmic /node: remotecomputer /user: username command
C:\>wmic /node:win7pcg /user:pearson
\administrator computersystem
               

Provides the username to be used during the session or for the command. You will be prompted to enter a password.

This is useful when connecting to remote systems, but it can't be used to change the credentials on the local system.

/password: password
wmic /node: remotecomputer 
/user: username
/password: password 
command
C:\>wmic /node:win7pcg /user:pearson
\administrator /password:P@ssw0rd
computersystem

Provides the password to be used with the specified user. This command must be used with a username.

/output: target [stdout | clipboard | file path and name]wmic /node:
remotecomputer 
/output:
target
command
C:\>wmic /node:win7pcg /output:clipboard
computersystem
C:\>wmic /node:win7pcg /output:filename
computersystem
C:\>wmic /node:win7pcg /output:c:\
scripts\test.txt computersystem

Identifies where to redirect the output. The output is normally sent to the screen but can be sent to the Clipboard or to a file. The /output switch needs to go before the alias.

When sending it to a file, the path must exist or the command will fail with an "Invalid file name" error.

C:\>wmic /node:win7pcg com-
putersystem > c:\scripts\
test.txt
/append: target [stdout | clipboard | file path and name] C:\>wmic /node:
remotecomputer /append:
filename command C:\>wmic /node:win7pcg /append:c:
\scripts\test.txt computersystem

Identifies where to redirect the output.

If the file doesn't exist, it will be created. If it does exist, the output is appended to the file.

When sending it to a file, the path must exist or the command will fail with an "Invalid file name" error.

  • + Share This
  • 🔖 Save To Your Account