Matt Hintzke
Matt Hintzke

Reputation: 8004

How to use mathematical operators on WMI query results?

I am doing some scripting for my company using BGInfo and am trying to figure out how to take a result of a WMI query and apply mathematical operators to it. For example, I am running the query:

SELECT AdapterRAM FROM Win32_VideoController

which evaluates to

268435456 (bytes)

However, I want this value to take the form of MB, so I want to divide this result by 1,048,576 to get

256 MB

Is there a way to do this?

Upvotes: 1

Views: 3164

Answers (2)

ravikanth
ravikanth

Reputation: 25810

As @RRUZ mentions, there is no support for arithmetic operators in WQL. However, in scirpting languages such as PowerShell, you can use the conversion units or multipliers to change the value from bytes to MB.

For example,

$adapterRAM = Get-WMIObject -Query "SELECT AdapterRAM FROM Win32_VideoController"
$adapterRAM.AdapterRAM/1MB

Updating the answer based on the comment below:

(Get-WMIObject -Query "SELECT AdapterRAM FROM Win32_VideoController").AdapterRam/1MB

If the above query results in multiple instances of Win32_VideoController, you have to index into the right instance. For example,

(Get-WMIObject -Query "SELECT AdapterRAM FROM Win32_VideoController")[0].AdapterRam/1MB

Upvotes: 0

RRUZ
RRUZ

Reputation: 136431

The WQL (the language used by the WMI) is only a subset of the SQL language, and doesn't support arithmetical operators, for more info you can check the WQL documentation .

Upvotes: 2

Related Questions