3

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?

lufist
  • 73
  • 1
  • 2
  • 9
  • 1
    Maybe this answer will help you https://stackoverflow.com/questions/57795873/how-do-i-get-access-to-cimcmdlets-in-net-core-when-using-system-management-auto – Lukasz Szczygielek Mar 05 '20 at 15:30
  • 1
    I suppose that is the advantage of wrapping the underlying api with friendly .NET classes. When they think it becomes important enough then they can change the wrapper implementation. So feel good about [the Nuget package](https://www.nuget.org/packages/System.Management/), .NETCore 2.0 and .NETStandard 2.0 supported. Why they didn't do this for PowerShell is unclear, I suspect they wanted to make it look familiar to devops that used the WMI tooling before. – Hans Passant Mar 05 '20 at 23:12
  • Note: they don't seem to be deprecating WMI as such, just the `*-Wmi*` family of commandlets. – SamB Aug 13 '23 at 15:47

1 Answers1

3

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.

Thraka
  • 2,065
  • 19
  • 24