Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been relying on these two commands:

wmic memorychip get capacity        // Outputs how much RAM there is (in a convoluted manner).
wmic diskdrive get Status,Model     // Checks whether the HDDs/SSDs on the system are (supposedly) still "OK" and working.

Today, I casually typed "wmic" to see if I could get JSON output to the above commands. The first thing it printed, in red text, was this:

WMIC is deprecated.

I was pretty shocked by this. It's deprecated? Alright... Then I definitely should not be relying on it. What are the "modern alternatives" for those two commands, then? Do they even exist? Why do they just tell us that it's "deprecated" with zero further information?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
533 views
Welcome To Ask or Share your Answers For Others

1 Answer

As mentioned in comments, WMIC is utility that acts as interface to communication with WMI. It's not WMI itself that is being deprecated, but "just" the interface. Since Microsoft is pushing PowerShell, I believe official successor wmic would be PowerShell commandlet Get-WmiObject. How to use this can be found on Microsoft documentation: LINK

[UPDATED] As correctly pointed out within comment, commandlet Get-WmiObject shall sunset one day and is not encouraged to be used. Only proper method is Get-CimInstance, which has pertty much same syntax as Get-WmiObject. See Microsoft documentation: LINK

For your particular case PowerShell alternative would be following:

wmic memorychip get capacity

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object capacity

wmic diskdrive get Status,Model

Get-CimInstance -ClassName Win32_diskdrive | Select-Object status, model

Commands in wmic are usually derived from WMI class names, but it's not really rule of thumb. With PowerShell you are accessing WMI by it's real class name instead, so you may need to seek for other classes if needed

Undisputed advantage to PowerShell over wmic is that output is an object and you can easily continue working with the output, while wmic returns a string only that you eventually need to parse for example if used inside scripts and that brings another benefit of e.g. output formatting - you can easily reformat any output for example to as you mentioned JSON, just pass your command through another pipe into commandlet ConvertTo-Json and you will have your expected output.

Example:

Get-CimInstance -ClassName Win32_diskdrive | select status, model | ConvertTo-JSON

Output:

{
    "status":  "OK",
    "model":  "SAMSUNG MZNTY256HDHP-000L7"
}

Hope this helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...