- 1 year ago
-List property in cmdlet Get-WmiObject
In PowerShell, the Get-WmiObject
cmdlet is used to retrieve WMI (Windows Management Instrumentation) objects on a Windows system. It allows you to query various system information and configuration data. To list properties of a WMI object obtained using Get-WmiObject
, you can use the Get-Member
cmdlet.
Here's how you can list properties of a WMI object:
Open a PowerShell session.
Use the
Get-WmiObject
cmdlet to retrieve the WMI object. For example, to get information about the operating system, you can use the following command:powershell$osInfo = Get-WmiObject Win32_OperatingSystem
Use the
Get-Member
cmdlet with the-MemberType Property
parameter to list the properties of the obtained WMI object. For example:powershell$osInfo | Get-Member -MemberType Property
This will display a list of properties available in the
$osInfo
object, which includes properties likeCaption
,Version
,BuildNumber
,Manufacturer
,SerialNumber
, etc.Sample Output:
vbnetTypeName: System.Management.ManagementObject#root\cimv2\Win32_OperatingSystem
Name MemberType Definition
---- ---------- ----------
BootDevice Property string BootDevice {get;set;}
BuildNumber Property string BuildNumber {get;set;}
BuildType Property string BuildType {get;set;}
Caption Property string Caption {get;set;}
.... (additional properties) ....
To access the value of a specific property, you can use dot notation. For example, to get the value of the
Caption
property:powershell$osInfo.Caption
This will display the name of the operating system, such as "Microsoft Windows 10 Pro."
Note: The Get-WmiObject
cmdlet is available in PowerShell versions up to 6.x. Starting from PowerShell Core 7.0, it is recommended to use the Get-CimInstance
cmdlet, which is an improved version of Get-WmiObject
. The Get-CimInstance
cmdlet works similarly, and you can use the same Get-Member
approach to list properties of the obtained CIM (Common Information Model) instances.