Filtering behaviour between CIM_ and Win32_ classes

Welcome Forums General PowerShell Q&A Filtering behaviour between CIM_ and Win32_ classes

This topic contains 6 replies, has 4 voices, and was last updated by

 
Participant
2 months, 3 weeks ago.

  • Author
    Posts
  • #108965

    Participant
    Points: 527
    Helping Hand
    Rank: Major Contributor

    What is the difference in filtering when using win32_ and CIM_ classes.

    [221]KVP> Get-CimInstance -ClassName CIM_LogicalDisk -Filter "VolumeName like 'O%'"
    Get-CimInstance : Invalid query
    At line:1 char:1
    + Get-CimInstance -ClassName CIM_LogicalDisk -Filter "VolumeName like ' ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-CimInstance], CimException
        + FullyQualifiedErrorId : HRESULT 0x80041017,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
    
    [242]KVP> Get-CimInstance -ClassName Win32_LogicalDisk -Filter "VolumeName like 'O%'"
    
    DeviceID DriveType ProviderName VolumeName Size         FreeSpace
    -------- --------- ------------ ---------- ----         ---------
    C:       3                      OSDisk     254916481024 109464317952
    S:       4         \\computer\s OSDisk     254916481024 109464317952
    
    
  • #108971

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    No, it's not a bug. See https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/cim-logicaldisk.

    CIM_LogicalDisk doesn't have a VolumeName property. That's why you're getting an error.

    In most cases, the CIM classes are "base classes," and are designed to be platform-neutral. The Win32_ version is Windows-specific, and adds a lot to the base class.

    • #108983

      Participant
      Points: 206
      Helping Hand
      Rank: Participant

      Interesting ...but.. but... but...

      So, even get-Member is a lie, as well as Select-Object???  Oh, the blasphemy.  8^}

      Wow, that kind of an ugly proposition, or odd Voodoo magic on retrieval attempts, if one was so inclined not to use the alternative.

          Get-CimInstance -ClassName CIM_LogicalDisk -Filter "DeviceID like 'D%'" | Get-Member -Force
      
      
             ---> TypeName: Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_LogicalDisk  VolumeName                   Property     string VolumeName {get;set;}  < ---
          ...
      
          
          Get-CimInstance -ClassName CIM_LogicalDisk -Filter "DeviceID like '%'" | Select-Object -Property VolumeName
      
          VolumeName
          ----------
          Root      
          Data      
          SDN       
          EVO4TB 
      
      
          (Get-CimInstance -ClassName CIM_LogicalDisk -Filter "DeviceID like '%'" | Select-Object -Property VolumeName) -Match 'D.*'
      
      
          VolumeName
          ----------
          Data      
          SDN 
      
      
          Get-CimInstance -ClassName CIM_LogicalDisk -Filter "DeviceID like '%'" | 
          Select-Object -Property VolumeName | 
          Where-Object -Property VolumeName -Match 'D.*'
      
          VolumeName
          ----------
          Data      
          SDN
  • #108973

    Participant
    Points: 527
    Helping Hand
    Rank: Major Contributor

    That's the info in the Doc and filter works perfect for all the documented properties, but how VolumeName is made available in the output ?

    [32]KVP> Get-CimInstance -ClassName CIM_LogicalDisk
    
    DeviceID DriveType ProviderName VolumeName Size         FreeSpace
    -------- --------- ------------ ---------- ----         ---------
    C:       3                      OSDisk     254916481024 109439442944
    S:       4         \\computer\s OSDisk     254916481024 109439442944
    
  • #108974

    Keymaster
    Points: 1,619
    Helping HandTeam Member
    Rank: Community Hero

    That's a combination of the repo and the CIM cmdlets doing some funky stuff under the hood to try and "make life easier." Doesn't always work out that way. Short answer: Query Win32_ classes when they're available, CIM_ when not.

  • #108977

    Participant
    Points: 527
    Helping Hand
    Rank: Major Contributor

    Yup, that's what I've decided, Thanks DJ for your time.

  • #108986

    Participant
    Points: 159
    Helping Hand
    Rank: Participant

    Worth noting that the reason VolumeName is still in the output although the CIM class doesn't have that property is that the cmdlets actually query the CIM class, and then convert it to the equivalent win32 class, adding the properties along the way.

You must be logged in to reply to this topic.