Get WmiObject - PowerShell
Overview
The Get-WmiObject
command retrieves Windows Management Instrumentation (WMI) objects from the local or remote computers. WMI provides a standardized interface for accessing management information and controlling system components. This command enables you to retrieve detailed information about various aspects of the system, including hardware, software, processes, and network configuration.
Syntax
Get-WmiObject [[-Class] <string>] [-Namespace <string>] [-Query <string>]
[-Authentication <Management.Credential>] [-AuthenticationLevel
<AuthenticationLevel>] [-ComputerName <string>] [-Credential <PSCredential>]
[-EnableAllPrivileges] [-Filter <string>] [-ImpersonationLevel
<ImpersonationLevel>] [-List] [-Property <string[]>] [-UseAmendedAuthentication]
[-UseNetBIOS] [-UseSsl] [-Verbose] [-WaitforComplete] [-ErrorAction <ActionPreference>]
[-WarningAction <ActionPreference>] [-WhatIf] [-Confirm]
Options/Flags
- -Class: Specifies the WMI class to retrieve objects from.
- -Namespace: Specifies the WMI namespace to use. Default: “root\cimv2”.
- -Query: Specifies a WQL query to filter the results.
- -Authentication: Specifies the credentials to use for authenticating with the remote computer if necessary.
- -AuthenticationLevel: Specifies the authentication level to use. Default: “Packet”.
- -ComputerName: Specifies the remote computer to retrieve WMI objects from. Default: Local computer.
- -Credential: Specifies the credential to use for authentication.
- -EnableAllPrivileges: Grants the command access to all privileges on the remote computer.
- -Filter: Specifies a filter to apply to the results.
- -ImpersonationLevel: Specifies the impersonation level to use. Default: Impersonate.
- -List: Lists the available WMI classes.
- -Property: Specifies the properties to retrieve from the objects.
- -UseAmendedAuthentication: Uses amended authentication when connecting to a remote computer.
- -UseNetBIOS: Uses NetBIOS to connect to the remote computer.
- -UseSsl: Uses SSL to connect to the remote computer.
- -Verbose: Outputs detailed information about the command’s execution.
- -WaitforComplete: Waits for the operation to complete before returning.
- -ErrorAction: Specifies the action to take when an error occurs.
- -WarningAction: Specifies the action to take when a warning occurs.
- -WhatIf: Shows what the command would do without executing it.
- -Confirm: Prompts for confirmation before executing the command.
Examples
Get all Win32_Process objects from the local computer:
Get-WmiObject -Class Win32_Process
Get the properties “Name” and “Description” for all Win32_Process objects:
Get-WmiObject -Class Win32_Process -Property Name,Description
Get all Win32_NetworkAdapter objects from a remote computer:
Get-WmiObject -Class Win32_NetworkAdapter -ComputerName remotecomputer
Filter results based on a WQL query:
Get-WmiObject -Class Win32_Service -Query "Name='wuauserv'"
Common Issues
- Permission Denied Errors: Ensure you have sufficient privileges to access the WMI information.
- Namespace Not Found Errors: Verify that the specified WMI namespace exists on the remote computer.
- Invalid Class Errors: Double-check the spelling and existence of the specified WMI class.
Integration
The Get-WmiObject
command can be integrated with other PowerShell commands to perform advanced system management tasks. For example, you can use it to:
- Monitor System Health: Get real-time information about system performance, resource usage, and event logs.
- Manage Registry: Retrieve and modify registry settings using WMI classes like
Win32_Registry
. - Hardware Inventory: Get detailed information about hardware components, including model, manufacturer, and serial numbers.
- Process Management: Start, stop, and terminate processes using the
Win32_Process
class. - Script Automation: Use
Get-WmiObject
in scripts to automate system administration tasks and gather diagnostic information.