WMIC - Command Line WMI and SMS

Most of my posts seem to come about because someone asks me how to do something, so yet again some one asked me if I knew a way to 'control' SMS / SCCM from the command line.


This got me thinking. Most of the scripts I write or use manipulate WMI in some way, either on the site server or on the client it's self.

After a bit of research I found a command called WMIC - Windows Management Instrumentation Command-line.

I am not going to delve to much into it as there are some pretty good articles on the Internet regarding WMIC.

Below I have summarised the command.

WMIC is more intuitive than WMI, in large part because of aliases. Aliases take simple commands that you enter at the command line, then act upon the WMI namespace in a predefined way, such as constructing a complex WMI Query Language (WQL) command from a simple WMIC alias Get command

Here is a little exercise to start you off.

1.  Run noptepad.exe
2.  Run WMIC (You will see that  Windows installs it on the computer and displays the WMIC command prompt wmic:root\cli>. )
3.  At the WMIC prompt type the following process where name='notepad.exe' call terminate

How easy is that, nice way to kill a process

After the command runs, the WMIC command prompt reappears.

Now I know that you lot are never happy, and I hear the question 'Thats great but how do I do it all in one command'

WMIC also runs in noninteractive mode. This mode is especially useful when you need to complete a single task or you need to run WMIC commands in a batch file. To run a command in noninteractive mode, you start WMIC and run the command in the same line of code.

wmic /node:machinename process where name='notepad.exe' call terminate

So what can you do with it as far as SMS / SCCM goes

I thought I would try a couple of the most common process that people seem to always want to trigger, hardware and software inventory

wmic /namespace:\\root\ccm path sms_client call triggerschedule "{00000000-0000-0000-0000-000000000001}" /nointeractive

wmic /namespace:\\root\ccm path sms_client call triggerschedule "{00000000-0000-0000-0000-000000000002}" /nointeractive

I suddenly thought if anyone else has done anything like this, so after a quick Goggle I found Roger Zander's blog
Where he explains all this, and lists some more SMS / SCCM commands you can do with WMIC, saves me writing about them and duplicating work.

I started this article about two months ago, just shows that I ought to finish them more quickly...

Filed under: , ,