One of my nuisance issues when using WMI with Windows PowerShell, is that when looking at all properties I have to wade though many that have no value. I'd prefer to only view properties that have a populated value. Here's one way.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Every WMI object has a property called Properties that is a collection of just what you would expect, properties.
[cc lang="PowerShell"]
PS S:\> gwmi win32_computersystem | Select Properties
Properties
----------
{AdminPasswordStatus, AutomaticManagedPagefile, AutomaticResetBootOption, AutomaticResetCapability...}
[/cc]
Because this is a collection, we can use Select-Object's ExpandProperty parameter.
[cc lang="PowerShell"]
PS S:\> gwmi win32_computersystem | Select -ExpandProperty Properties | select -first 2
Name : AdminPasswordStatus
Value : 0
Type : UInt16
IsLocal : True
IsArray : False
Origin : Win32_ComputerSystem
Qualifiers : {CIMTYPE}
Name : AutomaticManagedPagefile
Value : False
Type : Boolean
IsLocal : True
IsArray : False
Origin : Win32_ComputerSystem
Qualifiers : {CIMTYPE}
[/cc]
The object gives me the property name and any value. This means I can construct a PowerShell expression like this:
[cc lang="PowerShell"]
PS S:\> gwmi win32_computersystem | Select -ExpandProperty Properties | where {$_.value} | select Name,Value
Name Value
---- -----
AutomaticResetBootOption True
AutomaticResetCapability True
BootOptionOnLimit 3
BootOptionOnWatchDog 3
BootROMSupported True
BootupState Normal boot
Caption SERENITY
ChassisBootupState 3
CreationClassName Win32_ComputerSystem
CurrentTimeZone -240
DaylightInEffect True
Description AT/AT COMPATIBLE
DNSHostName SERENITY
Domain WORKGROUP
EnableDaylightSavingsTime True
FrontPanelResetStatus 3
KeyboardPasswordStatus 3
Manufacturer TOSHIBA
Model Qosmio X505
Name SERENITY
NetworkServerModeEnabled True
NumberOfLogicalProcessors 8
NumberOfProcessors 1
OEMStringArray ... , Bd-BtD7SW5M3i, bM5oVNHGZz+S9, yGkIbhav0zUFP}
PauseAfterReset 3932100000
PCSystemType 2
PowerSupplyState 3
PrimaryOwnerName Prof. Powershell
ResetCapability 1
ResetCount -1
ResetLimit -1
Roles {LM_Workstation, LM_Server, SQLServer, NT}
Status OK
SystemType x64-based PC
ThermalState 3
TotalPhysicalMemory 8577855488
UserName SERENITY\Jeff
WakeUpType 6
Workgroup WORKGROUP
[/cc]
All I've done is pipe the collection of properties to Where-Object which is filtering out any objects that do not have a value. This is the type of thing where a scriptblock or function would come in handy.
[cc lang="PowerShell"]
PS S:\> $wmi={Param([string]$class) gwmi $class | Select -ExpandProperty Properties | where {$_.value} | Select Name,Value}
PS S:\> &$wmi win32_bios
Name Value
---- -----
BiosCharacteristics {4, 7, 8, 9...}
BIOSVersion {TOSQCI - 6040000, Ver 1.00PARTTBL}
Caption Ver 1.00PARTTBL
Description Ver 1.00PARTTBL
Manufacturer TOSHIBA
Name Ver 1.00PARTTBL
PrimaryBIOS True
ReleaseDate 20101210000000.000000+000
SerialNumber Z9131790W
SMBIOSBIOSVersion V2.90
SMBIOSMajorVersion 2
SMBIOSMinorVersion 6
SMBIOSPresent True
SoftwareElementID Ver 1.00PARTTBL
SoftwareElementState 3
Status OK
Version TOSQCI - 6040000
[/cc]
I'll let you play with this and add support for remote computers or alternate credentials.