MSFT_NetAdapter Invalid class
Asked Answered
P

1

7

I am trying to use new WMI-class in Windows 8 MSFT_NetAdapter instead of Win32_NetworkAdapter

using System;
using System.Management;

namespace TestAdapters
{
    class Program
    {
        static void Main(string[] args)
        {
            string query = "SELECT * From MSFT_NetAdapter";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection adaptersCollection = searcher.Get();
            foreach (ManagementObject adapterWmiObject in adaptersCollection) //System.Management.ManagementException
            {
                //...
            }
            Console.WriteLine("end.");
            Console.ReadKey();
        }
    }
}

And I get an System.Management.ManagementException on the the foreach statement with message: Invalid class

I don't know, what does it mean. I compiled and ran code under Windows 8.1 x64, so this class must work.

How to use MSFT_NetAdapter?

Postobit answered 20/1, 2014 at 14:7 Comment(0)
A
11

This class is not in the root\Cimv2 namespace.

Look for it in the root\StandardCimv2 namespace.

Look at the following Powershell:

PS C:\Scripts> Get-WmiObject MSFT_NetAdapter
Get-WmiObject : Invalid class "MSFT_NetAdapter"
At line:1 char:1
+ Get-WmiObject MSFT_NetAdapter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand


PS C:\Scripts> Get-WmiObject MSFT_NetAdapter -Namespace root\StandardCimv2
SUCCESS
Augustina answered 10/3, 2014 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.