Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSFT_NetAdapter Invalid class

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?

like image 937
Anatolii Humennyi Avatar asked Jan 20 '14 14:01

Anatolii Humennyi


1 Answers

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
like image 190
Ryan Ries Avatar answered Sep 21 '22 11:09

Ryan Ries