locked
Win32_ComputerSystem can not retrieve VM list in Server 2012 R2 RRS feed

  • Question

  • Below code use to work on Win2008 or 2012. Recently, I upgraded my system to WIn2012 R2, the ManagementObjectCollection will throw "invalid class" exception. Any clue to fix this?

    ObjectQuery  query = new ObjectQuery("SELECT * FROM MsVM_ComputerSystem WHERE Caption LIKE 'Virtual%' ");
    using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(manScope, query))
                    {
    ManagementObjectCollection collection = searcher.Get();
    if (collection != null)
    {
     foreach (ManagementObject obj in collection)
     { 

    Tuesday, December 24, 2013 10:36 AM