Win32_PortableBattery

The Win32_PortableBattery WMI class contains the properties related to a portable battery, such as a notebook computer battery.

The Win32_PortableBattery WMI class contains the properties related to a portable battery, such as a notebook computer battery.

Methods

Win32_PortableBattery has no methods. Inherited methods (Reset and SetPowerState) are not implemented.

Properties

Win32_PortableBattery returns 37 properties:

'Availability','BatteryStatus','CapacityMultiplier','Caption','Chemistry',
'ConfigManagerErrorCode','ConfigManagerUserConfig','CreationClassName','Description','DesignCapacity',
'DesignVoltage','DeviceID','ErrorCleared','ErrorDescription','EstimatedChargeRemaining',
'EstimatedRunTime','ExpectedBatteryLife','ExpectedLife','FullChargeCapacity','InstallDate',
'LastErrorCode','Location','ManufactureDate','Manufacturer','MaxBatteryError','MaxRechargeTime',
'Name','PNPDeviceID','PowerManagementCapabilities','PowerManagementSupported',
'SmartBatteryVersion','Status','StatusInfo','SystemCreationClassName','SystemName','TimeOnBattery',
'TimeToFullCharge'

Unless explicitly marked as writeable, all properties are read-only. Read all properties for all instances:

Get-CimInstance -ClassName Win32_PortableBattery -Property *

Most WMI classes return one or more instances.

When Get-CimInstance returns no result, then apparently no instances of class Win32_PortableBattery exist. This is normal behavior.

Either the class is not implemented on your system (may be deprecated or due to missing drivers, i.e. CIM_VideoControllerResolution), or there are simply no physical representations of this class currently available (i.e. Win32_TapeDrive).

Availability

UINT16

Availability and status of the device.

Availability returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$Availability_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Running/Full Power'
      4 = 'Warning'
      5 = 'In Test'
      6 = 'Not Applicable'
      7 = 'Power Off'
      8 = 'Off Line'
      9 = 'Off Duty'
     10 = 'Degraded'
     11 = 'Not Installed'
     12 = 'Install Error'
     13 = 'Power Save - Unknown'
     14 = 'Power Save - Low Power Mode'
     15 = 'Power Save - Standby'
     16 = 'Power Cycle'
     17 = 'Power Save - Warning'
     18 = 'Paused'
     19 = 'Not Ready'
     20 = 'Not Configured'
     21 = 'Quiesced'
}
Use a switch statement
switch([int]$value)
{
  1          {'Other'}
  2          {'Unknown'}
  3          {'Running/Full Power'}
  4          {'Warning'}
  5          {'In Test'}
  6          {'Not Applicable'}
  7          {'Power Off'}
  8          {'Off Line'}
  9          {'Off Duty'}
  10         {'Degraded'}
  11         {'Not Installed'}
  12         {'Install Error'}
  13         {'Power Save - Unknown'}
  14         {'Power Save - Low Power Mode'}
  15         {'Power Save - Standby'}
  16         {'Power Cycle'}
  17         {'Power Save - Warning'}
  18         {'Paused'}
  19         {'Not Ready'}
  20         {'Not Configured'}
  21         {'Quiesced'}
  default    {"$value"}
}
Use Enum structure
Enum EnumAvailability
{
  Other                       = 1
  Unknown                     = 2
  RunningFull_Power           = 3
  Warning                     = 4
  In_Test                     = 5
  Not_Applicable              = 6
  Power_Off                   = 7
  Off_Line                    = 8
  Off_Duty                    = 9
  Degraded                    = 10
  Not_Installed               = 11
  Install_Error               = 12
  Power_Save_Unknown          = 13
  Power_Save_Low_Power_Mode   = 14
  Power_Save_Standby          = 15
  Power_Cycle                 = 16
  Power_Save_Warning          = 17
  Paused                      = 18
  Not_Ready                   = 19
  Not_Configured              = 20
  Quiesced                    = 21
}

Examples

Use $Availability_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "Availability" to friendly text

  Note: to use other properties than "Availability", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Availability" 
# to translate other properties, use their translation table instead
$Availability_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Running/Full Power'
      4 = 'Warning'
      5 = 'In Test'
      6 = 'Not Applicable'
      7 = 'Power Off'
      8 = 'Off Line'
      9 = 'Off Duty'
     10 = 'Degraded'
     11 = 'Not Installed'
     12 = 'Install Error'
     13 = 'Power Save - Unknown'
     14 = 'Power Save - Low Power Mode'
     15 = 'Power Save - Standby'
     16 = 'Power Cycle'
     17 = 'Power Save - Warning'
     18 = 'Paused'
     19 = 'Not Ready'
     20 = 'Not Configured'
     21 = 'Quiesced'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "Availability", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$Availability = @{
  Name = 'Availability'
  Expression = {
    # property is an array, so process all values
    $value = $_.Availability
    $Availability_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "Availability". The latter
# is defined by the hashtable in $Availability: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $Availability

# ...or dump content of property Availability:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $Availability |
    Select-Object -ExpandProperty Availability

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $Availability_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$Availability_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Running/Full Power'
      4 = 'Warning'
      5 = 'In Test'
      6 = 'Not Applicable'
      7 = 'Power Off'
      8 = 'Off Line'
      9 = 'Off Duty'
     10 = 'Degraded'
     11 = 'Not Installed'
     12 = 'Install Error'
     13 = 'Power Save - Unknown'
     14 = 'Power Save - Low Power Mode'
     15 = 'Power Save - Standby'
     16 = 'Power Cycle'
     17 = 'Power Save - Warning'
     18 = 'Paused'
     19 = 'Not Ready'
     20 = 'Not Configured'
     21 = 'Quiesced'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.Availability  

# translate raw value to friendly text:
$friendlyName = $Availability_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "Availability" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "Availability", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "Availability", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$Availability = @{
  Name = 'Availability'
  Expression = {
    # property is an array, so process all values
    $value = $_.Availability
    
    switch([int]$value)
      {
        1          {'Other'}
        2          {'Unknown'}
        3          {'Running/Full Power'}
        4          {'Warning'}
        5          {'In Test'}
        6          {'Not Applicable'}
        7          {'Power Off'}
        8          {'Off Line'}
        9          {'Off Duty'}
        10         {'Degraded'}
        11         {'Not Installed'}
        12         {'Install Error'}
        13         {'Power Save - Unknown'}
        14         {'Power Save - Low Power Mode'}
        15         {'Power Save - Standby'}
        16         {'Power Cycle'}
        17         {'Power Save - Warning'}
        18         {'Paused'}
        19         {'Not Ready'}
        20         {'Not Configured'}
        21         {'Quiesced'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "Availability". The latter is defined
  # by the hashtable in $Availability:
  Select-Object -Property Caption, $Availability
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumAvailability
{
  Other                       = 1
  Unknown                     = 2
  RunningFull_Power           = 3
  Warning                     = 4
  In_Test                     = 5
  Not_Applicable              = 6
  Power_Off                   = 7
  Off_Line                    = 8
  Off_Duty                    = 9
  Degraded                    = 10
  Not_Installed               = 11
  Install_Error               = 12
  Power_Save_Unknown          = 13
  Power_Save_Low_Power_Mode   = 14
  Power_Save_Standby          = 15
  Power_Cycle                 = 16
  Power_Save_Warning          = 17
  Paused                      = 18
  Not_Ready                   = 19
  Not_Configured              = 20
  Quiesced                    = 21
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.Availability

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **Availability** 
[EnumAvailability]$rawValue 

# get a comma-separated string:
[EnumAvailability]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumAvailability]
#endregion

Enums must cover all possible values. If Availability returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

BatteryStatus

UINT16

Description of the battery’s charge status. The value 10 (Undefined) is not valid in the Common Information Model (CIM) schema because in Desktop Management Interface (DMI) it indicates that no battery is installed. In this case, this object should not be instantiated.

BatteryStatus returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$BatteryStatus_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Fully Charged'
      4 = 'Low'
      5 = 'Critical'
      6 = 'Charging'
      7 = 'Charging and High'
      8 = 'Charging and Low'
      9 = 'Charging and Critical'
     10 = 'Undefined'
     11 = 'Partially Charged'
}
Use a switch statement
switch([int]$value)
{
  1          {'Other'}
  2          {'Unknown'}
  3          {'Fully Charged'}
  4          {'Low'}
  5          {'Critical'}
  6          {'Charging'}
  7          {'Charging and High'}
  8          {'Charging and Low'}
  9          {'Charging and Critical'}
  10         {'Undefined'}
  11         {'Partially Charged'}
  default    {"$value"}
}
Use Enum structure
Enum EnumBatteryStatus
{
  Other                   = 1
  Unknown                 = 2
  Fully_Charged           = 3
  Low                     = 4
  Critical                = 5
  Charging                = 6
  Charging_and_High       = 7
  Charging_and_Low        = 8
  Charging_and_Critical   = 9
  Undefined               = 10
  Partially_Charged       = 11
}

Examples

Use $BatteryStatus_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "BatteryStatus" to friendly text

  Note: to use other properties than "BatteryStatus", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "BatteryStatus" 
# to translate other properties, use their translation table instead
$BatteryStatus_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Fully Charged'
      4 = 'Low'
      5 = 'Critical'
      6 = 'Charging'
      7 = 'Charging and High'
      8 = 'Charging and Low'
      9 = 'Charging and Critical'
     10 = 'Undefined'
     11 = 'Partially Charged'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "BatteryStatus", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$BatteryStatus = @{
  Name = 'BatteryStatus'
  Expression = {
    # property is an array, so process all values
    $value = $_.BatteryStatus
    $BatteryStatus_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "BatteryStatus". The latter
# is defined by the hashtable in $BatteryStatus: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $BatteryStatus

# ...or dump content of property BatteryStatus:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $BatteryStatus |
    Select-Object -ExpandProperty BatteryStatus

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $BatteryStatus_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$BatteryStatus_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Fully Charged'
      4 = 'Low'
      5 = 'Critical'
      6 = 'Charging'
      7 = 'Charging and High'
      8 = 'Charging and Low'
      9 = 'Charging and Critical'
     10 = 'Undefined'
     11 = 'Partially Charged'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.BatteryStatus  

# translate raw value to friendly text:
$friendlyName = $BatteryStatus_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "BatteryStatus" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "BatteryStatus", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "BatteryStatus", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$BatteryStatus = @{
  Name = 'BatteryStatus'
  Expression = {
    # property is an array, so process all values
    $value = $_.BatteryStatus
    
    switch([int]$value)
      {
        1          {'Other'}
        2          {'Unknown'}
        3          {'Fully Charged'}
        4          {'Low'}
        5          {'Critical'}
        6          {'Charging'}
        7          {'Charging and High'}
        8          {'Charging and Low'}
        9          {'Charging and Critical'}
        10         {'Undefined'}
        11         {'Partially Charged'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "BatteryStatus". The latter is defined
  # by the hashtable in $BatteryStatus:
  Select-Object -Property Caption, $BatteryStatus
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumBatteryStatus
{
  Other                   = 1
  Unknown                 = 2
  Fully_Charged           = 3
  Low                     = 4
  Critical                = 5
  Charging                = 6
  Charging_and_High       = 7
  Charging_and_Low        = 8
  Charging_and_Critical   = 9
  Undefined               = 10
  Partially_Charged       = 11
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.BatteryStatus

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **BatteryStatus** 
[EnumBatteryStatus]$rawValue 

# get a comma-separated string:
[EnumBatteryStatus]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumBatteryStatus]
#endregion

Enums must cover all possible values. If BatteryStatus returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

CapacityMultiplier

UINT16

Multiplication factor of the DesignCapacity value to ensure that the milliwatt hour value does not overflow for Smart Battery Data Specification (SBDS) implementations.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, CapacityMultiplier

Caption

STRING MAX 64 CHAR

Short description of the object—a one-line string.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Caption

Chemistry

UINT16

Chemistry of the battery.

Chemistry returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$Chemistry_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Lead Acid'
      4 = 'Nickel Cadmium'
      5 = 'Nickel Metal Hydride'
      6 = 'Lithium-ion'
      7 = 'Zinc air'
      8 = 'Lithium Polymer'
}
Use a switch statement
switch([int]$value)
{
  1          {'Other'}
  2          {'Unknown'}
  3          {'Lead Acid'}
  4          {'Nickel Cadmium'}
  5          {'Nickel Metal Hydride'}
  6          {'Lithium-ion'}
  7          {'Zinc air'}
  8          {'Lithium Polymer'}
  default    {"$value"}
}
Use Enum structure
Enum EnumChemistry
{
  Other                  = 1
  Unknown                = 2
  Lead_Acid              = 3
  Nickel_Cadmium         = 4
  Nickel_Metal_Hydride   = 5
  Lithium_ion            = 6
  Zinc_air               = 7
  Lithium_Polymer        = 8
}

Examples

Use $Chemistry_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "Chemistry" to friendly text

  Note: to use other properties than "Chemistry", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Chemistry" 
# to translate other properties, use their translation table instead
$Chemistry_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Lead Acid'
      4 = 'Nickel Cadmium'
      5 = 'Nickel Metal Hydride'
      6 = 'Lithium-ion'
      7 = 'Zinc air'
      8 = 'Lithium Polymer'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "Chemistry", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$Chemistry = @{
  Name = 'Chemistry'
  Expression = {
    # property is an array, so process all values
    $value = $_.Chemistry
    $Chemistry_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "Chemistry". The latter
# is defined by the hashtable in $Chemistry: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $Chemistry

# ...or dump content of property Chemistry:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $Chemistry |
    Select-Object -ExpandProperty Chemistry

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $Chemistry_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$Chemistry_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Lead Acid'
      4 = 'Nickel Cadmium'
      5 = 'Nickel Metal Hydride'
      6 = 'Lithium-ion'
      7 = 'Zinc air'
      8 = 'Lithium Polymer'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.Chemistry  

# translate raw value to friendly text:
$friendlyName = $Chemistry_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "Chemistry" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "Chemistry", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "Chemistry", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$Chemistry = @{
  Name = 'Chemistry'
  Expression = {
    # property is an array, so process all values
    $value = $_.Chemistry
    
    switch([int]$value)
      {
        1          {'Other'}
        2          {'Unknown'}
        3          {'Lead Acid'}
        4          {'Nickel Cadmium'}
        5          {'Nickel Metal Hydride'}
        6          {'Lithium-ion'}
        7          {'Zinc air'}
        8          {'Lithium Polymer'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "Chemistry". The latter is defined
  # by the hashtable in $Chemistry:
  Select-Object -Property Caption, $Chemistry
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumChemistry
{
  Other                  = 1
  Unknown                = 2
  Lead_Acid              = 3
  Nickel_Cadmium         = 4
  Nickel_Metal_Hydride   = 5
  Lithium_ion            = 6
  Zinc_air               = 7
  Lithium_Polymer        = 8
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.Chemistry

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **Chemistry** 
[EnumChemistry]$rawValue 

# get a comma-separated string:
[EnumChemistry]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumChemistry]
#endregion

Enums must cover all possible values. If Chemistry returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

ConfigManagerErrorCode

UINT32

Win32 Configuration Manager error code.

ConfigManagerErrorCode returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$ConfigManagerErrorCode_map = @{
      0 = 'This device is working properly.'
      1 = 'This device is not configured correctly.'
      2 = 'Windows cannot load the driver for this device.'
      3 = 'The driver for this device might be corrupted, or your system may be running low on memory or other resources.'
      4 = 'This device is not working properly. One of its drivers or your registry might be corrupted.'
      5 = 'The driver for this device needs a resource that Windows cannot manage.'
      6 = 'The boot configuration for this device conflicts with other devices.'
      7 = 'Cannot filter.'
      8 = 'The driver loader for the device is missing.'
      9 = 'This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'
     10 = 'This device cannot start.'
     11 = 'This device failed.'
     12 = 'This device cannot find enough free resources that it can use.'
     13 = 'Windows cannot verify this device''s resources.'
     14 = 'This device cannot work properly until you restart your computer.'
     15 = 'This device is not working properly because there is probably a re-enumeration problem.'
     16 = 'Windows cannot identify all the resources this device uses.'
     17 = 'This device is asking for an unknown resource type.'
     18 = 'Reinstall the drivers for this device.'
     19 = 'Failure using the VxD loader.'
     20 = 'Your registry might be corrupted.'
     21 = 'System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'
     22 = 'This device is disabled.'
     23 = 'System failure: Try changing the driver for this device. If that doesn''t work, see your hardware documentation.'
     24 = 'This device is not present, is not working properly, or does not have all its drivers installed.'
     25 = 'Windows is still setting up this device.'
     26 = 'Windows is still setting up this device.'
     27 = 'This device does not have valid log configuration.'
     28 = 'The drivers for this device are not installed.'
     29 = 'This device is disabled because the firmware of the device did not give it the required resources.'
     30 = 'This device is using an Interrupt Request (IRQ) resource that another device is using.'
     31 = 'This device is not working properly because Windows cannot load the drivers required for this device.'
}
Use a switch statement
switch([int]$value)
{
  0          {'This device is working properly.'}
  1          {'This device is not configured correctly.'}
  2          {'Windows cannot load the driver for this device.'}
  3          {'The driver for this device might be corrupted, or your system may be running low on memory or other resources.'}
  4          {'This device is not working properly. One of its drivers or your registry might be corrupted.'}
  5          {'The driver for this device needs a resource that Windows cannot manage.'}
  6          {'The boot configuration for this device conflicts with other devices.'}
  7          {'Cannot filter.'}
  8          {'The driver loader for the device is missing.'}
  9          {'This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'}
  10         {'This device cannot start.'}
  11         {'This device failed.'}
  12         {'This device cannot find enough free resources that it can use.'}
  13         {'Windows cannot verify this device''s resources.'}
  14         {'This device cannot work properly until you restart your computer.'}
  15         {'This device is not working properly because there is probably a re-enumeration problem.'}
  16         {'Windows cannot identify all the resources this device uses.'}
  17         {'This device is asking for an unknown resource type.'}
  18         {'Reinstall the drivers for this device.'}
  19         {'Failure using the VxD loader.'}
  20         {'Your registry might be corrupted.'}
  21         {'System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'}
  22         {'This device is disabled.'}
  23         {'System failure: Try changing the driver for this device. If that doesn''t work, see your hardware documentation.'}
  24         {'This device is not present, is not working properly, or does not have all its drivers installed.'}
  25         {'Windows is still setting up this device.'}
  26         {'Windows is still setting up this device.'}
  27         {'This device does not have valid log configuration.'}
  28         {'The drivers for this device are not installed.'}
  29         {'This device is disabled because the firmware of the device did not give it the required resources.'}
  30         {'This device is using an Interrupt Request (IRQ) resource that another device is using.'}
  31         {'This device is not working properly because Windows cannot load the drivers required for this device.'}
  default    {"$value"}
}
Use Enum structure
Enum EnumConfigManagerErrorCode
{
  This_device_is_working_properly                              = 0
  This_device_is_not_configured_correctly                      = 1
  Windows_cannot_load_the_driver_for_this_device               = 2
  The_driver_for_this_device_might_be_corrupted_or_your_system_may_be_running_low_on_memory_or_other_resources = 3
  This_device_is_not_working_properly_One_of_its_drivers_or_your_registry_might_be_corrupted = 4
  The_driver_for_this_device_needs_a_resource_that_Windows_cannot_manage = 5
  The_boot_configuration_for_this_device_conflicts_with_other_devices = 6
  Cannot_filter                                                = 7
  The_driver_loader_for_the_device_is_missing                  = 8
  This_device_is_not_working_properly_because_the_controlling_firmware_is_reporting_the_resources_for_the_device_incorrectly = 9
  This_device_cannot_start                                     = 10
  This_device_failed                                           = 11
  This_device_cannot_find_enough_free_resources_that_it_can_use = 12
  Windows_cannot_verify_this_devices_resources                 = 13
  This_device_cannot_work_properly_until_you_restart_your_computer = 14
  This_device_is_not_working_properly_because_there_is_probably_a_re_enumeration_problem = 15
  Windows_cannot_identify_all_the_resources_this_device_uses   = 16
  This_device_is_asking_for_an_unknown_resource_type           = 17
  Reinstall_the_drivers_for_this_device                        = 18
  Failure_using_the_VxD_loader                                 = 19
  Your_registry_might_be_corrupted                             = 20
  System_failure_Try_changing_the_driver_for_this_device_If_that_does_not_work_see_your_hardware_documentation_Windows_is_removing_this_device = 21
  This_device_is_disabled                                      = 22
  System_failure_Try_changing_the_driver_for_this_device_If_that_doesnt_work_see_your_hardware_documentation = 23
  This_device_is_not_present_is_not_working_properly_or_does_not_have_all_its_drivers_installed = 24
  Windows_is_still_setting_up_this_device1                     = 25
  Windows_is_still_setting_up_this_device2                     = 26
  This_device_does_not_have_valid_log_configuration            = 27
  The_drivers_for_this_device_are_not_installed                = 28
  This_device_is_disabled_because_the_firmware_of_the_device_did_not_give_it_the_required_resources = 29
  This_device_is_using_an_Interrupt_Request_IRQ_resource_that_another_device_is_using = 30
  This_device_is_not_working_properly_because_Windows_cannot_load_the_drivers_required_for_this_device = 31
}

Examples

Use $ConfigManagerErrorCode_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "ConfigManagerErrorCode" to friendly text

  Note: to use other properties than "ConfigManagerErrorCode", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "ConfigManagerErrorCode" 
# to translate other properties, use their translation table instead
$ConfigManagerErrorCode_map = @{
      0 = 'This device is working properly.'
      1 = 'This device is not configured correctly.'
      2 = 'Windows cannot load the driver for this device.'
      3 = 'The driver for this device might be corrupted, or your system may be running low on memory or other resources.'
      4 = 'This device is not working properly. One of its drivers or your registry might be corrupted.'
      5 = 'The driver for this device needs a resource that Windows cannot manage.'
      6 = 'The boot configuration for this device conflicts with other devices.'
      7 = 'Cannot filter.'
      8 = 'The driver loader for the device is missing.'
      9 = 'This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'
     10 = 'This device cannot start.'
     11 = 'This device failed.'
     12 = 'This device cannot find enough free resources that it can use.'
     13 = 'Windows cannot verify this device''s resources.'
     14 = 'This device cannot work properly until you restart your computer.'
     15 = 'This device is not working properly because there is probably a re-enumeration problem.'
     16 = 'Windows cannot identify all the resources this device uses.'
     17 = 'This device is asking for an unknown resource type.'
     18 = 'Reinstall the drivers for this device.'
     19 = 'Failure using the VxD loader.'
     20 = 'Your registry might be corrupted.'
     21 = 'System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'
     22 = 'This device is disabled.'
     23 = 'System failure: Try changing the driver for this device. If that doesn''t work, see your hardware documentation.'
     24 = 'This device is not present, is not working properly, or does not have all its drivers installed.'
     25 = 'Windows is still setting up this device.'
     26 = 'Windows is still setting up this device.'
     27 = 'This device does not have valid log configuration.'
     28 = 'The drivers for this device are not installed.'
     29 = 'This device is disabled because the firmware of the device did not give it the required resources.'
     30 = 'This device is using an Interrupt Request (IRQ) resource that another device is using.'
     31 = 'This device is not working properly because Windows cannot load the drivers required for this device.'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "ConfigManagerErrorCode", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$ConfigManagerErrorCode = @{
  Name = 'ConfigManagerErrorCode'
  Expression = {
    # property is an array, so process all values
    $value = $_.ConfigManagerErrorCode
    $ConfigManagerErrorCode_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "ConfigManagerErrorCode". The latter
# is defined by the hashtable in $ConfigManagerErrorCode: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $ConfigManagerErrorCode

# ...or dump content of property ConfigManagerErrorCode:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $ConfigManagerErrorCode |
    Select-Object -ExpandProperty ConfigManagerErrorCode

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $ConfigManagerErrorCode_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$ConfigManagerErrorCode_map = @{
      0 = 'This device is working properly.'
      1 = 'This device is not configured correctly.'
      2 = 'Windows cannot load the driver for this device.'
      3 = 'The driver for this device might be corrupted, or your system may be running low on memory or other resources.'
      4 = 'This device is not working properly. One of its drivers or your registry might be corrupted.'
      5 = 'The driver for this device needs a resource that Windows cannot manage.'
      6 = 'The boot configuration for this device conflicts with other devices.'
      7 = 'Cannot filter.'
      8 = 'The driver loader for the device is missing.'
      9 = 'This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'
     10 = 'This device cannot start.'
     11 = 'This device failed.'
     12 = 'This device cannot find enough free resources that it can use.'
     13 = 'Windows cannot verify this device''s resources.'
     14 = 'This device cannot work properly until you restart your computer.'
     15 = 'This device is not working properly because there is probably a re-enumeration problem.'
     16 = 'Windows cannot identify all the resources this device uses.'
     17 = 'This device is asking for an unknown resource type.'
     18 = 'Reinstall the drivers for this device.'
     19 = 'Failure using the VxD loader.'
     20 = 'Your registry might be corrupted.'
     21 = 'System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'
     22 = 'This device is disabled.'
     23 = 'System failure: Try changing the driver for this device. If that doesn''t work, see your hardware documentation.'
     24 = 'This device is not present, is not working properly, or does not have all its drivers installed.'
     25 = 'Windows is still setting up this device.'
     26 = 'Windows is still setting up this device.'
     27 = 'This device does not have valid log configuration.'
     28 = 'The drivers for this device are not installed.'
     29 = 'This device is disabled because the firmware of the device did not give it the required resources.'
     30 = 'This device is using an Interrupt Request (IRQ) resource that another device is using.'
     31 = 'This device is not working properly because Windows cannot load the drivers required for this device.'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.ConfigManagerErrorCode  

# translate raw value to friendly text:
$friendlyName = $ConfigManagerErrorCode_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "ConfigManagerErrorCode" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "ConfigManagerErrorCode", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "ConfigManagerErrorCode", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$ConfigManagerErrorCode = @{
  Name = 'ConfigManagerErrorCode'
  Expression = {
    # property is an array, so process all values
    $value = $_.ConfigManagerErrorCode
    
    switch([int]$value)
      {
        0          {'This device is working properly.'}
        1          {'This device is not configured correctly.'}
        2          {'Windows cannot load the driver for this device.'}
        3          {'The driver for this device might be corrupted, or your system may be running low on memory or other resources.'}
        4          {'This device is not working properly. One of its drivers or your registry might be corrupted.'}
        5          {'The driver for this device needs a resource that Windows cannot manage.'}
        6          {'The boot configuration for this device conflicts with other devices.'}
        7          {'Cannot filter.'}
        8          {'The driver loader for the device is missing.'}
        9          {'This device is not working properly because the controlling firmware is reporting the resources for the device incorrectly.'}
        10         {'This device cannot start.'}
        11         {'This device failed.'}
        12         {'This device cannot find enough free resources that it can use.'}
        13         {'Windows cannot verify this device''s resources.'}
        14         {'This device cannot work properly until you restart your computer.'}
        15         {'This device is not working properly because there is probably a re-enumeration problem.'}
        16         {'Windows cannot identify all the resources this device uses.'}
        17         {'This device is asking for an unknown resource type.'}
        18         {'Reinstall the drivers for this device.'}
        19         {'Failure using the VxD loader.'}
        20         {'Your registry might be corrupted.'}
        21         {'System failure: Try changing the driver for this device. If that does not work, see your hardware documentation. Windows is removing this device.'}
        22         {'This device is disabled.'}
        23         {'System failure: Try changing the driver for this device. If that doesn''t work, see your hardware documentation.'}
        24         {'This device is not present, is not working properly, or does not have all its drivers installed.'}
        25         {'Windows is still setting up this device.'}
        26         {'Windows is still setting up this device.'}
        27         {'This device does not have valid log configuration.'}
        28         {'The drivers for this device are not installed.'}
        29         {'This device is disabled because the firmware of the device did not give it the required resources.'}
        30         {'This device is using an Interrupt Request (IRQ) resource that another device is using.'}
        31         {'This device is not working properly because Windows cannot load the drivers required for this device.'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "ConfigManagerErrorCode". The latter is defined
  # by the hashtable in $ConfigManagerErrorCode:
  Select-Object -Property Caption, $ConfigManagerErrorCode
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumConfigManagerErrorCode
{
  This_device_is_working_properly                              = 0
  This_device_is_not_configured_correctly                      = 1
  Windows_cannot_load_the_driver_for_this_device               = 2
  The_driver_for_this_device_might_be_corrupted_or_your_system_may_be_running_low_on_memory_or_other_resources = 3
  This_device_is_not_working_properly_One_of_its_drivers_or_your_registry_might_be_corrupted = 4
  The_driver_for_this_device_needs_a_resource_that_Windows_cannot_manage = 5
  The_boot_configuration_for_this_device_conflicts_with_other_devices = 6
  Cannot_filter                                                = 7
  The_driver_loader_for_the_device_is_missing                  = 8
  This_device_is_not_working_properly_because_the_controlling_firmware_is_reporting_the_resources_for_the_device_incorrectly = 9
  This_device_cannot_start                                     = 10
  This_device_failed                                           = 11
  This_device_cannot_find_enough_free_resources_that_it_can_use = 12
  Windows_cannot_verify_this_devices_resources                 = 13
  This_device_cannot_work_properly_until_you_restart_your_computer = 14
  This_device_is_not_working_properly_because_there_is_probably_a_re_enumeration_problem = 15
  Windows_cannot_identify_all_the_resources_this_device_uses   = 16
  This_device_is_asking_for_an_unknown_resource_type           = 17
  Reinstall_the_drivers_for_this_device                        = 18
  Failure_using_the_VxD_loader                                 = 19
  Your_registry_might_be_corrupted                             = 20
  System_failure_Try_changing_the_driver_for_this_device_If_that_does_not_work_see_your_hardware_documentation_Windows_is_removing_this_device = 21
  This_device_is_disabled                                      = 22
  System_failure_Try_changing_the_driver_for_this_device_If_that_doesnt_work_see_your_hardware_documentation = 23
  This_device_is_not_present_is_not_working_properly_or_does_not_have_all_its_drivers_installed = 24
  Windows_is_still_setting_up_this_device1                     = 25
  Windows_is_still_setting_up_this_device2                     = 26
  This_device_does_not_have_valid_log_configuration            = 27
  The_drivers_for_this_device_are_not_installed                = 28
  This_device_is_disabled_because_the_firmware_of_the_device_did_not_give_it_the_required_resources = 29
  This_device_is_using_an_Interrupt_Request_IRQ_resource_that_another_device_is_using = 30
  This_device_is_not_working_properly_because_Windows_cannot_load_the_drivers_required_for_this_device = 31
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.ConfigManagerErrorCode

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **ConfigManagerErrorCode** 
[EnumConfigManagerErrorCode]$rawValue 

# get a comma-separated string:
[EnumConfigManagerErrorCode]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumConfigManagerErrorCode]
#endregion

Enums must cover all possible values. If ConfigManagerErrorCode returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

ConfigManagerUserConfig

BOOLEAN

If TRUE, the device is using a user-defined configuration.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ConfigManagerUserConfig

CreationClassName

STRING

Name of the first concrete class that appears in the inheritance chain used in the creation of an instance. When used with the other key properties of the class, the property allows all instances of this class and its subclasses to be uniquely identified.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, CreationClassName

Description

STRING

Description of the object.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Description

DesignCapacity

UINT32 “MILLIWATT-HOURS”

Design capacity of the battery in milliwatt-hours. If this property is not supported, enter 0 (zero).

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, DesignCapacity

DesignVoltage

UINT64 “MILLIVOLTS”

Design voltage of the battery in millivolts. If this attribute is not supported, enter 0 (zero).

For more information about using uint64 values in scripts, see Scripting in WMI.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, DesignVoltage

DeviceID

KEY PROPERTY STRING

Battery identifier.

Example: “Internal Battery”

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID

ErrorCleared

BOOLEAN

If TRUE, the error reported in LastErrorCode is now cleared.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ErrorCleared

ErrorDescription

STRING

More information about the error recorded in LastErrorCode, and any corrective actions that may be taken.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ErrorDescription

EstimatedChargeRemaining

UINT16 “PERCENT”

Estimate of the percentage of full charge remaining.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, EstimatedChargeRemaining

EstimatedRunTime

UINT32 “MINUTES”

Estimate in minutes of the time to battery charge depletion under the present load conditions if the utility power is off, or lost and remains off, or a laptop is disconnected from a power source.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, EstimatedRunTime

ExpectedBatteryLife

UINT32

Not supported.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ExpectedBatteryLife

ExpectedLife

UINT32 “MINUTES”

Battery’s expected lifetime in minutes, assuming that the battery is fully charged. This property represents the total expected life of the battery, not its current remaining life, which is indicated by the EstimatedRunTime property.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ExpectedLife

FullChargeCapacity

UINT32 “MILLIWATT-HOURS”

Full charge capacity of the battery in milliwatt-hours. Comparison of this value to the DesignCapacity property determines when the battery requires replacement. A battery’s end of life is typically when the FullChargeCapacity property falls below 80% of the DesignCapacity property. If this property is not supported, enter 0 (zero).

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, FullChargeCapacity

InstallDate

DATETIME

Date and time the object was installed. This property does not need a value to indicate that the object is installed.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, InstallDate

LastErrorCode

UINT32

Last error code reported by the logical device.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, LastErrorCode

Location

STRING

Physical location of the battery. This property is filled by the computer manufacturer.

Example: “In the back, on the left”

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Location

ManufactureDate

STRING

Date when the battery was manufactured.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, ManufactureDate

Manufacturer

STRING

Manufacturer of the battery.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Manufacturer

MaxBatteryError

UINT16 “PERCENT”

Difference between the highest estimated amount of energy left in the battery and the current amount reported by the battery.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, MaxBatteryError

MaxRechargeTime

UINT32 “MINUTES”

Maximum time, in minutes, to fully charge the battery. This property represents the time to recharge a fully depleted battery, not the current remaining charge time, which is indicated in the TimeToFullCharge property.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, MaxRechargeTime

Name

STRING

Label by which the object is known. When subclassed, the property can be overridden to be a key property.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Name

PNPDeviceID

STRING

Windows Plug and Play device identifier of the logical device.

Example: “*PNP030b”

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, PNPDeviceID

PowerManagementCapabilities

UINT16 ARRAY

Array of the specific power-related capabilities of a logical device.

PowerManagementCapabilities returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$PowerManagementCapabilities_map = @{
      0 = 'Unknown'
      1 = 'Not Supported'
      2 = 'Disabled'
      3 = 'Enabled'
      4 = 'Power Saving Modes Entered Automatically'
      5 = 'Power State Settable'
      6 = 'Power Cycling Supported'
      7 = 'Timed Power On Supported'
}
Use a switch statement
switch([int]$value)
{
  0          {'Unknown'}
  1          {'Not Supported'}
  2          {'Disabled'}
  3          {'Enabled'}
  4          {'Power Saving Modes Entered Automatically'}
  5          {'Power State Settable'}
  6          {'Power Cycling Supported'}
  7          {'Timed Power On Supported'}
  default    {"$value"}
}
Use Enum structure
Enum EnumPowerManagementCapabilities
{
  Unknown                                    = 0
  Not_Supported                              = 1
  Disabled                                   = 2
  Enabled                                    = 3
  Power_Saving_Modes_Entered_Automatically   = 4
  Power_State_Settable                       = 5
  Power_Cycling_Supported                    = 6
  Timed_Power_On_Supported                   = 7
}

Examples

Use $PowerManagementCapabilities_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "PowerManagementCapabilities" to friendly text

  Note: to use other properties than "PowerManagementCapabilities", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "PowerManagementCapabilities" 
# to translate other properties, use their translation table instead
$PowerManagementCapabilities_map = @{
      0 = 'Unknown'
      1 = 'Not Supported'
      2 = 'Disabled'
      3 = 'Enabled'
      4 = 'Power Saving Modes Entered Automatically'
      5 = 'Power State Settable'
      6 = 'Power Cycling Supported'
      7 = 'Timed Power On Supported'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "PowerManagementCapabilities", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$PowerManagementCapabilities = @{
  Name = 'PowerManagementCapabilities'
  Expression = {
    # property is an array, so process all values
    $result = foreach($value in $_.PowerManagementCapabilities)
    {
        # important: convert original value to [int] because
        # hashtable keys are type-aware:
        $PowerManagementCapabilities_map[[int]$value]
    }
    # uncomment to get a comma-separated string instead
    # of a string array:
    $result <#-join ', '#>
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "PowerManagementCapabilities". The latter
# is defined by the hashtable in $PowerManagementCapabilities: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $PowerManagementCapabilities

# ...or dump content of property PowerManagementCapabilities:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $PowerManagementCapabilities |
    Select-Object -ExpandProperty PowerManagementCapabilities

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $PowerManagementCapabilities_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when there
  is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$PowerManagementCapabilities_map = @{
      0 = 'Unknown'
      1 = 'Not Supported'
      2 = 'Disabled'
      3 = 'Enabled'
      4 = 'Power Saving Modes Entered Automatically'
      5 = 'Power State Settable'
      6 = 'Power Cycling Supported'
      7 = 'Timed Power On Supported'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property (hint: the property is an array!)
$rawValues = $instance.PowerManagementCapabilities  

# translate all raw values into friendly names:
$friendlyNames = foreach($rawValue in $rawValues)
{ $PowerManagementCapabilities_map[[int]$rawValue] }

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "PowerManagementCapabilities" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "PowerManagementCapabilities", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "PowerManagementCapabilities", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$PowerManagementCapabilities = @{
  Name = 'PowerManagementCapabilities'
  Expression = {
    # property is an array, so process all values
    $result = foreach($value in $_.PowerManagementCapabilities)
    {
        switch([int]$value)
      {
        0          {'Unknown'}
        1          {'Not Supported'}
        2          {'Disabled'}
        3          {'Enabled'}
        4          {'Power Saving Modes Entered Automatically'}
        5          {'Power State Settable'}
        6          {'Power Cycling Supported'}
        7          {'Timed Power On Supported'}
        default    {"$value"}
      }
      
    }
    $result
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "PowerManagementCapabilities". The latter is defined
  # by the hashtable in $PowerManagementCapabilities:
  Select-Object -Property Caption, $PowerManagementCapabilities
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumPowerManagementCapabilities
{
  Unknown                                    = 0
  Not_Supported                              = 1
  Disabled                                   = 2
  Enabled                                    = 3
  Power_Saving_Modes_Entered_Automatically   = 4
  Power_State_Settable                       = 5
  Power_Cycling_Supported                    = 6
  Timed_Power_On_Supported                   = 7
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.PowerManagementCapabilities

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **PowerManagementCapabilities** 
[EnumPowerManagementCapabilities[]]$rawValue 

# get a comma-separated string:
[EnumPowerManagementCapabilities[]]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumPowerManagementCapabilities[]]
#endregion

Enums must cover all possible values. If PowerManagementCapabilities returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

PowerManagementSupported

BOOLEAN

If TRUE, the device can be power-managed (can be put into suspend mode, and so on). The property does not indicate that power management features are currently enabled, only that the logical device is capable of power management.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, PowerManagementSupported

SmartBatteryVersion

STRING MAX 64 CHAR

Smart Battery Data Specification version number supported by this battery. If the battery does not support this function, the value should be left blank.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, SmartBatteryVersion

Status

STRING MAX 10 CHAR

Current status of an object. Various operational and nonoperational statuses can be defined. Available values:

$values = 'Degraded','Error','Lost Comm','No Contact','NonRecover','OK','Pred Fail','Service','Starting','Stopping','Stressed','Unknown'
Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, Status

StatusInfo

UINT16

State of the logical device. If this property does not apply to the logical device, the value 5 (Not Applicable) should be used.

StatusInfo returns a numeric value. To translate it into a meaningful text, use any of the following approaches:

Use a PowerShell Hashtable
$StatusInfo_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Enabled'
      4 = 'Disabled'
      5 = 'Not Applicable'
}
Use a switch statement
switch([int]$value)
{
  1          {'Other'}
  2          {'Unknown'}
  3          {'Enabled'}
  4          {'Disabled'}
  5          {'Not Applicable'}
  default    {"$value"}
}
Use Enum structure
Enum EnumStatusInfo
{
  Other            = 1
  Unknown          = 2
  Enabled          = 3
  Disabled         = 4
  Not_Applicable   = 5
}

Examples

Use $StatusInfo_map in a calculated property for Select-Object
<# 
  this example uses a hashtable to translate raw numeric values for 
  property "StatusInfo" to friendly text

  Note: to use other properties than "StatusInfo", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "StatusInfo" 
# to translate other properties, use their translation table instead
$StatusInfo_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Enabled'
      4 = 'Disabled'
      5 = 'Not Applicable'
}

#endregion define hashtable

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "StatusInfo", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$StatusInfo = @{
  Name = 'StatusInfo'
  Expression = {
    # property is an array, so process all values
    $value = $_.StatusInfo
    $StatusInfo_map[[int]$value]
  }  
}
#endregion define calculated property

# retrieve the instances, and output the properties "Caption" and "StatusInfo". The latter
# is defined by the hashtable in $StatusInfo: 
Get-CimInstance -Class Win32_PortableBattery | Select-Object -Property Caption, $StatusInfo

# ...or dump content of property StatusInfo:
$friendlyValues = Get-CimInstance -Class Win32_PortableBattery | 
    Select-Object -Property $StatusInfo |
    Select-Object -ExpandProperty StatusInfo

# output values
$friendlyValues

# output values as comma separated list
$friendlyValues -join ', '

# output values as bullet list
$friendlyValues | ForEach-Object { "- $_" }
Use $StatusInfo_map to directly translate raw values from an instance
<# 
  this example uses a hashtable to manually translate raw numeric values 
  for property "Win32_PortableBattery" to friendly text. This approach is ideal when
  there is just one instance to work with.

  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  translation hashtable for the property you would like to use instead.
#>

#region define hashtable to translate raw values to friendly text

# Please note: this hashtable is specific for property "Win32_PortableBattery" 
# to translate other properties, use their translation table instead
$StatusInfo_map = @{
      1 = 'Other'
      2 = 'Unknown'
      3 = 'Enabled'
      4 = 'Disabled'
      5 = 'Not Applicable'
}

#endregion define hashtable

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to illustrate
  the number-to-text translation. To process all instances, replace
  "Select-Object -First 1" with a "Foreach-Object" loop, and use
  the iterator variable $_ instead of $instance
#>

# query the property
$rawValue = $instance.StatusInfo  

# translate raw value to friendly text:
$friendlyName = $StatusInfo_map[[int]$rawValue]

# output value
$friendlyName
Use a switch statement inside a calculated property for Select-Object
<# 
  this example uses a switch clause to translate raw numeric 
  values for property "StatusInfo" to friendly text. The switch
  clause is embedded into a calculated property so there is
  no need to refer to external variables for translation.

  Note: to use other properties than "StatusInfo", look up the appropriate 
  translation switch clause for the property you would like to use instead.
#>

#region define calculated property (to be used with Select-Object)

<#
  a calculated property is defined by a hashtable with keys "Name" and "Expression"
  "Name" defines the name of the property (in this example, it is "StatusInfo", but you can rename it to anything else)
  "Expression" defines a scriptblock that calculates the content of this property
  in this example, the scriptblock uses the hashtable defined earlier to translate each numeric
  value to its friendly text counterpart:
#>
 
$StatusInfo = @{
  Name = 'StatusInfo'
  Expression = {
    # property is an array, so process all values
    $value = $_.StatusInfo
    
    switch([int]$value)
      {
        1          {'Other'}
        2          {'Unknown'}
        3          {'Enabled'}
        4          {'Disabled'}
        5          {'Not Applicable'}
        default    {"$value"}
      }
      
  }  
}
#endregion define calculated property

# retrieve all instances...
Get-CimInstance -ClassName Win32_PortableBattery | 
  # ...and output properties "Caption" and "StatusInfo". The latter is defined
  # by the hashtable in $StatusInfo:
  Select-Object -Property Caption, $StatusInfo
Use the Enum from above to auto-translate the code values
<# 
  this example translates raw values by means of type conversion
  the friendly names are defined as enumeration using the
  keyword "enum" (PowerShell 5 or better)
  
  The raw value(s) are translated to friendly text by 
  simply converting them into the enum type.
  
  Note: to use other properties than "Win32_PortableBattery", look up the appropriate 
  enum definition for the property you would like to use instead.
#>


#region define enum with value-to-text translation:
Enum EnumStatusInfo
{
  Other            = 1
  Unknown          = 2
  Enabled          = 3
  Disabled         = 4
  Not_Applicable   = 5
}

#endregion define enum

# get one instance:
$instance = Get-CimInstance -Class Win32_PortableBattery | Select-Object -First 1

<#
  IMPORTANT: this example processes only one instance to focus on
  the number-to-text type conversion. 
  
  To process all instances, replace   "Select-Object -First 1" 
  with a "Foreach-Object" loop, and use the iterator variable 
  $_ instead of $instance
#>

# query the property:
$rawValue = $instance.StatusInfo

#region using strict type conversion

<#
  Note: strict type conversion fails if the raw value is 
  not defined by the enum. So if the list of allowable values
  was extended and the enum does not match the value,
  an exception is thrown
#>

# convert the property to the enum **StatusInfo** 
[EnumStatusInfo]$rawValue 

# get a comma-separated string:
[EnumStatusInfo]$rawValue -join ',' 
#endregion

#region using operator "-as"

<#
  Note: the operator "-as" accepts values not defined
  by the enum and returns $null instead of throwing
  an exception
#>

$rawValue -as [EnumStatusInfo]
#endregion

Enums must cover all possible values. If StatusInfo returns a value that is not defined in the enum, an exception occurs. The exception reports the value that was missing in the enum. To fix, add the missing value to the enum.

SystemCreationClassName

STRING

Value of the scoping computer’s CreationClassName property.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, SystemCreationClassName

SystemName

STRING

Name of the scoping system.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, SystemName

TimeOnBattery

UINT32 “SECONDS”

Elapsed time in seconds since the computer system’s UPS last switched to battery power, or the time since the system or UPS was last restarted, whichever is less. If the battery is online, 0 (zero) is returned.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, TimeOnBattery

TimeToFullCharge

UINT32 “MINUTES”

Remaining time in minutes to charge the battery fully at the current charge rate and usage.

Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property DeviceID, TimeToFullCharge

Examples

List all instances of Win32_PortableBattery
Get-CimInstance -ClassName Win32_PortableBattery

Learn more about Get-CimInstance and the deprecated Get-WmiObject.

View all properties
Get-CimInstance -ClassName Win32_PortableBattery -Property *
View key properties only
Get-CimInstance -ClassName Win32_PortableBattery -KeyOnly

Selecting Properties

To select only some properties, pipe the results to Select-Object -Property a,b,c with a comma-separated list of the properties you require. Wildcards are permitted.

Get-CimInstance always returns all properties but only retrieves the ones that you specify. All other properties are empty but still present. That’s why you need to pipe the results into Select-Object if you want to limit the visible properties, i.e. for reporting.

Selecting Properties

The code below lists all available properties. Remove the ones you do not need:

$properties = 'Availability',
              'BatteryStatus',
              'CapacityMultiplier',
              'Caption',
              'Chemistry',
              'ConfigManagerErrorCode',
              'ConfigManagerUserConfig',
              'CreationClassName',
              'Description',
              'DesignCapacity',
              'DesignVoltage',
              'DeviceID',
              'ErrorCleared',
              'ErrorDescription',
              'EstimatedChargeRemaining',
              'EstimatedRunTime',
              'ExpectedBatteryLife',
              'ExpectedLife',
              'FullChargeCapacity',
              'InstallDate',
              'LastErrorCode',
              'Location',
              'ManufactureDate',
              'Manufacturer',
              'MaxBatteryError',
              'MaxRechargeTime',
              'Name',
              'PNPDeviceID',
              'PowerManagementCapabilities',
              'PowerManagementSupported',
              'SmartBatteryVersion',
              'Status',
              'StatusInfo',
              'SystemCreationClassName',
              'SystemName',
              'TimeOnBattery',
              'TimeToFullCharge'
Get-CimInstance -ClassName Win32_PortableBattery | Select-Object -Property $properties
Limiting Network Bandwidth

If you work remotely, it makes sense to limit network bandwidth by filtering the properties on the server side, too:

Get-CimInstance -Class Win32_PortableBattery -Property $property | 
Select-Object -Property $property

Selecting Instances

To select some instances, use Get-CimInstance and a WMI Query. The wildcard character in WMI Queries is % (and not “*”).

The parameter -Filter runs a simple query.

Listing all instances where the property Caption starts with “A”
Get-CimInstance -Class Win32_PortableBattery -Filter 'Caption LIKE "a%"' 
Using a WQL Query

The parameter -Query uses a query similar to SQL and combines the parameters -Filter and -Property. This returns all instances where the property Caption starts with “A”, and returns the properties specified:

Get-CimInstance -Query "SELECT ErrorCleared, FullChargeCapacity, Location, StatusInfo FROM Win32_PortableBattery WHERE Caption LIKE 'a%'"

Any property you did not specify is still present but empty. You might need to use Select-Object to remove all unwanted properties:

Get-CimInstance -Query "SELECT ErrorCleared, FullChargeCapacity, Location, StatusInfo FROM Win32_PortableBattery WHERE Caption LIKE 'a%'" | Select-Object -Property ErrorCleared, FullChargeCapacity, Location, StatusInfo

Accessing Remote Computers

To access remote systems, you need to have proper permissions. User the parameter -ComputerName to access one or more remote systems.

Authenticating as Current User
# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with your current identity:
$result = Get-CimInstance -ClassName Win32_PortableBattery -ComputerName $list 
$result
Authenticating as Different User

Use a CIMSession object to authenticate with a new identity:

# one or more computer names or IP addresses:
$list = 'server1', 'server2'

# authenticate with a different identity:
$cred = Get-Credential -Message 'Authenticate to retrieve WMI information:'
$session = New-CimSession -ComputerName $list -Credential $cred

$result = Get-CimInstance Win32_PortableBattery -CimSession $session

# remove the session after use (if you do not plan to re-use it later)
Remove-CimSession -CimSession $session

$result

Learn more about accessing remote computers.

Requirements

To use Win32_PortableBattery, the following requirements apply:

PowerShell

Get-CimInstance was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.

If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.

Operating System

Win32_PortableBattery was introduced on clients with Windows Vista and on servers with Windows Server 2008.

Namespace

Win32_PortableBattery lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance.

Implementation

Win32_PortableBattery is implemented in CIMWin32.dll and defined in CIMWin32.mof. Both files are located in the folder C:\Windows\system32\wbem:

explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\CIMWin32.mof