WMI Calls From Linux Friday, August 15, 2008
Posted by Félim in Linux, Microsoft, Ubuntu.Tags: Linux, WMI
trackback
sudo aptitude install wmi-client
Example of usage is;
wmic -U DOMAIN/administrator%password //10.99.92.9 “Select * from Win32_Service”
Lists all services, the first line it spits back is the fields which you can use this SQL like language to filter, so to see only the names of the services installed we’d do:
wmic -U DOMAIN/administrator%password //10.99.92.9 “Select Name from Win32_Service”
Or Name and State:
wmic -U DOMAIN/administrator%password //10.99.92.9 “Select Name,State from Win32_Service”
Or for just one service in this case the UPS service:
wmic -U DOMAIN/administrator%password //10.99.92.9 “Select Name,State from Win32_Service where name=’UPS’”
The language for the queries is called WQL and a reference is available here over at MSDN.
Hope this helps, this is only in Hardy as far as I’m aware.

Great tip! i didn’t know the existance of this tool! Thanks, our mixed environment will benefit from this
Does it it need the WMI Mapper from HP installed on the target windows machine or does it actually utilize the proprietary M$ WMI interface?
It uses the default Windows stuff which comes as default in the installation (Unless your company/OEM tweaked it, but unlikely) and that’s it, so nothing needs modified on the Windows side at all.
I’ve been querying message boards all over the place and not getting any answers, so I thought I’d try here. I have the client and it works OK, however when I try to query for an IP address using:
wmic -U DOMAIN/username%password //machine “SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = ‘TRUE’”
The results look like:
Index|IPAddress
12|Unsupported
16|Unsupported
I turned up samba debugging and I’m seeing the correct values being returned. They’re just not being displayed by the client.
It seems to do this with all properties that are returned as arrays. I really don’t want to implement a WMI mapper. This program gave me a ton of hope.
Thanks.
Have you had any luck getting this working with a Server 2008 remote host?
I’ve had none at all Ross, I’ve even tried latest SVN version to see if there was any change.. none unfortunately.
Only query for use the command… my question is if its possible excecute methods from any class like Win_Process
You can run a SELECT alright, but whether the Terminate process method for instance works I am not sure. But perhps you’d be better off with winexe in that case ?
Hi,
do you have any additional informations about the wmic programm for linux ?
I’ve read your blog post about reading values and service states from windows,
but do you have informations about setting values or taking actions on the windows host,
like restarting services, setting network options or similar?
Is it possible with wmic?
Do you know any addtional informations, who used the programm and wrote about
his experiences with it?
As far as I can tell it’s not possible, but if you take a look at my other article about winexe you can actually run a command prompt on the Windows host, so you could restart services that way. The wmi-client was written by the Zenoss guys (http://dev.zenoss.com/trac/log/trunk/wmi/), it’s a hacked together bunch of components from Samba4. Winexe is a similar sort of thing. It’s very easy to use and with XP/2003 onwards it’s fairly possable to control everything via comandline for the majority of tasks.