How to Show All Properties of a PowerShell Object
-
Use
Get-WmiObject
to Show All Properties of a PowerShell Object - Retrieve the Class Instance/Object Information
-
Use the
Format-List
Cmdlet to Display Properties - Conclusion
There are requirements to find information about the Windows machine and its components, such as network, application, and services. The Common Information Model (CIM) is an open-source standard for manipulating these components and their information.
Microsoft has implemented its standard on top of CIM called Windows Management Instrumentation (WMI) to query and manipulate computer, service, and network information.
Use Get-WmiObject
to Show All Properties of a PowerShell Object
The Get-WmiObject
cmdlet is a powerful tool, particularly for system administration and management tasks. It allows access to Windows Management Instrumentation (WMI) data, which includes a wealth of information about the system, such as details about hardware, installed software, network configuration, and more.
One of the lesser-known yet potent capabilities of Get-WmiObject
is using the -List
parameter. This option enables users to retrieve a list of all WMI classes within a specified namespace.
The basic syntax of Get-WmiObject -List
is:
Get-WmiObject -List [-Namespace <String>] [-ComputerName <String>]
Key parameters include:
-Namespace <String>
: Specifies the WMI repository namespace. The default isroot\cimv2
, which contains most of the commonly used WMI classes.-ComputerName <String>
: Targets a remote computer. Without this parameter, the cmdlet operates on the local machine.
Hence, the Windows system management process becomes a lot easier. Let’s check the available classes using the Get-WmiObject
cmdlet.
Get-WmiObject -List
This command will output all the classes available in the default namespace of your local machine. The default namespace is ROOT\cimv2
in the Windows computer.
Output:
It is possible to specify a different namespace other than the default one (ROOT\cimv2
). We can use the -Namespace
parameter to change the default namespace.
Get-WmiObject -Namespace <custom_namespace>
Retrieve the Class Instance/Object Information
The use of Get-WmiObject -Class
is primarily for retrieving detailed information about a particular aspect of the system. For instance, querying the Win32_Processor
class provides information about the processor, while Win32_OperatingSystem
reveals details about the OS.
The -Class
parameter of this cmdlet allows users to query specific classes within the WMI repository, which are essentially templates for the objects that represent system information. These classes cover a wide range of data, from hardware details to configuration settings.
Syntax:
Get-WmiObject -Class <String> [-Namespace <String>] [-ComputerName <String>]
Key parameters include:
-Class <String>
: Specifies the WMI class for which information is required.-Namespace <String>
: Optional. Specifies the WMI repository namespace (default isroot\cimv2
).-ComputerName <String>
: Optional. Directs the command to a remote computer.
There are hundreds of WMI classes available to use. We can retrieve the information for a given class, as shown in the following.
Get-WmiObject -Class Win32_computersystem
Here, we are retrieving information for the Win32_computersystem
class. It returns the Win32_computersystem
object with its properties, which holds all the information about the computer system, as shown in the following.
There are a limited number of properties shown in the output. The Win32_computersystem
object contains more properties than these.
We can use the Format-List
cmdlet to display all the properties of a retrieved object.
Use the Format-List
Cmdlet to Display Properties
The Format-List
can be piped with the output of another command to format the results. This cmdlet can display the specified or all the properties of a retrieved WMI object in a readable format.
Syntax:
Get-WmiObject -Class Win32_computersystem | Format-List -Property Name, Model, Manufacturer
Let’s specify some properties for the Win32_computersystem
instance.
Format-List [-Property <PropertyName[]>]
: Formats the output as a list.-Property <PropertyName[]>
: (Optional) Specifies the properties to display. If omitted, all properties are shown.
Output:
The Get-WmiObject
returns the default properties for the Win32_computersystem
object. Then, the output will be passed through the pipeline operator (|
) to the Format-List
command.
We can pass the -Property
parameter to the Format-List
cmdlet. That will filter out the final output with the given three properties.
Sometimes, it is important to check all the properties and values available for a specified WMI object. In that case, you need to use -Property *
to retrieve all the available properties and their values.
The *
indicates all properties.
Get-WmiObject -Class Win32_computersystem | Format-List -Property *
Output:
The output contains all the properties and the values available for the Win32_computersystem
object. We can omit the -Property
parameter in the above command and write it.
Get-WmiObject -Class Win32_computersystem | Format-List *
The above command should display the same output as above.
Conclusion
In this exploration of PowerShell’s Get-WmiObject
, we’ve uncovered its pivotal role in Windows system management. The -List
parameter empowers users to enumerate all WMI classes, aiding in the identification of relevant data sources.
Focusing on -Class
, we demonstrated its precision in retrieving detailed system information, exemplified with Win32_ComputerSystem
. The addition of Format-List
enhances output readability, which is crucial when dealing with extensive property lists.
To deepen your knowledge, delve into various WMI classes like Win32_Processor
or Win32_OperatingSystem
. Incorporating Get-WmiObject
into scripts can streamline system management tasks.
As a versatile tool, Get-WmiObject
caters to both beginners and seasoned users, epitomizing its significance in PowerShell for diverse IT tasks and automation.
Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.