windows.net-corewmicim

WMI deprecated: how to query from .Net Core now?


I've read here that Microsoft is deprecating WMI. I need to start a project in .NET Core and query information from Windows, e.g. Win32_OperatingSystem or Win32_LogicalDisk.

I'v read that you should avoid Get-WmiObject in PowerShell and use Get-CimInstance instead. What (which Nuget/library) should be used in .Net Core now to query those kind of information?


Solution

  • You can use the Windows Compatibility Pack (article, nuget) for .NET Core which gives you access to a lot of Windows-only APIs but restricts your app to running only on Windows, probably not something you're worried about. This compatibility pack is also known as platform extensions. With this you would need to learn how to use the classes in the System.Management namespace (API Ref, example code 1, example code 2). Keep exploring the API for examples.

    Additionally, it looks like there is a newer cross-platform open-source system similar to CIM made by Microsoft. Though apparently not everything available in WMI is available with this, so your mileage will vary: https://www.nuget.org/packages/Microsoft.Management/ and https://www.nuget.org/packages/Microsoft.Management.Infrastructure/

    Hope this helps.