Return to site

Wmi Equivalent For Mac

broken image


Windows Management Instrumentation (WMI) is the infrastructure for management data and operations on Windows-based operating systems. You can write WMI scripts or applications to automate administrative tasks on remote computers but WMI also supplies management data to other parts of the operating system and products.

The Basics¶

The following are 30 code examples for showing how to use wmi.WMI.These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. In a previous article about WMI filters for Group Policy, I identified simple filters to make sure that GPOs will only apply to machines running a specific operating system such as Windows 7. This is helpful for separating workstations based on OS, but one of the most commonly asked for filter is whether the client is running on laptop. Spiceworks can produce a list of software installed, patches, AV any much anything else a WMI scan can pull Rod-IT, are forgetting about Local Group Policy and Local Security Policy? You can definitely use ADMX/ADML templates for those. Kdean, what do you use to get the equivalent information for Macs? If all you need is reporting PowerShell is.

We’re not really going to be looking at what you can do with WMI in general, except by way of demonstrating somefunctionality within the module. There are no few examples around the web of what you can do with the technology(and you can do most things with it if you try hard enough). Some links are at the bottom of the document.

Connecting¶

Most of the time, you’ll simply connect to the local machine with the defaults:

Wmi Equivalent For Mac

Wmi Equivalent For Mac Os

If you need to connect to a different machine, specify its name as the first parameter:

Mac

Wmi Equivalent For Mac Os

If you need to connect to a different machine, specify its name as the first parameter:

Querying¶

The most common thing you’ll be doing with WMI is finding out about various parts of your system. That involvesdetermining which WMI class to interrogate and then treating that as an attribute of the Python WMI object:

The “which WMI class to interrogate” part of that earlier sentence is not always so easy as it sounds. However,with a good search engine at your disposal, you can be pretty much assured that someone somewhere has done the samething as you albeit with a different language. There are some helpful links at the bottom of this document, but Ioften simply stick “WMI thing-to-do” into my search engine of choice and scan the results for convincing answers.

Wmi Equivalent For Mac Shortcut

Note that, although there is only, in this case, one Operating System, a WMI query always returns a list, possiblyof one item. The items in the list are wrapped by the Python module for attribute access. In this case, theWin32_OperatingSystem class has several attributes, one of which is .Caption, which refers to the name of theinstalled OS.

Wmi Equivalent For Mac High Sierra

Monitoring¶

WMI has the concept of events. There are two types, intrinsic and extrinsic, which are discussed below. The Pythonmodule makes the difference as transparent as it can. Say you wanted to track new processes starting up:

Note that you must pass one of “creation”, “deletion”, “modification” or “operation” to the .watch_for method. Ifnot, slightly odd errors will result.

New in version 1.3.1: If you don’t specify a notification type to an intrinsic event then“operation” will be assumed, which triggers on any change to an object of that class.

Updating¶

Some, but by no means all, WMI classes allow for the possibility of writing information back. This you do bysetting attributes as usual in Python. Note that the class may let you do this without complaint even thoughnothing useful has happened. To change the display name of a service, for example, you need to call the service’s.Change method. You can update the displayName attribute directly without error, but it will have no effect.

The most typical place in which you’ll set an attribute directly is when you’re creating a whole new object from aclass’s .new method. In that case you can either set all the parameters as keyword arguments to the .new call oryou can specify them one by one afterwards.

Methods¶

Wmi Equivalent For Macs

Some WMI classes have methods to operate on them. You can call them as though they were normal class or instancemethods in Python. From version 1.3.1, parameters can be positioned; before that, they must be named. If you wantedto stop the (running) RunAs service, whose short name is “seclogon”:





broken image