Search code examples
powershellwmiwmi-query

How to discover device properties and their powershell/WMI equivalent?


I have this powershell code (I didn't write it) :

$nics = Get-WmiObject Win32_NetworkAdapter -filter "AdapterTypeID = '0' `
                                                    AND PhysicalAdapter = 'true' `
                                                    AND NOT Description LIKE '%Centrino%' `
                                                    AND NOT Description LIKE '%wireless%' `
                                                    AND NOT Description LIKE '%WiFi%' `
                                                    AND NOT Description LIKE '%Bluetooth%'"


foreach ($nic in $nics)
  {
  $nicName = $nic.Name
   ...
}

Question

How did the author knew that the NIC has those properties :

  • Win32_NetworkAdapter
  • AdapterTypeID
  • PhysicalAdapter
  • Description

In other words : How can I inspect all the properties that NIC/Other_Device has ?


Solution

  • get-member or (gm) gets you all properties:

    PS C:\Users\bjorn> Get-WmiObject Win32_NetworkAdapter | gm
    
    
       TypeName: System.Management.ManagementObject#root\cimv2\Win32_NetworkAdapter
    
    Name                        MemberType    Definition                                                                                        
    ----                        ----------    ----------                                                                                        
    PSComputerName              AliasProperty PSComputerName = __SERVER                                                                         
    Disable                     Method        System.Management.ManagementBaseObject Disable()                                                  
    Enable                      Method        System.Management.ManagementBaseObject Enable()                                                   
    Reset                       Method        System.Management.ManagementBaseObject Reset()                                                    
    SetPowerState               Method        System.Management.ManagementBaseObject SetPowerState(System.UInt16 PowerState, System.String Time)
    AdapterType                 Property      string AdapterType {get;set;}                                                                     
    AdapterTypeId               Property      uint16 AdapterTypeId {get;set;}                                                                   
    AutoSense                   Property      bool AutoSense {get;set;}                                                                         
    Availability                Property      uint16 Availability {get;set;}    
    ...
    

    or with e.g. the ISESteroids plugin:

    enter image description here