Get-WmiObject

Get WMI class information, instances of classes or available classes. Alias: gwmi

Syntax
      Get-WmiObject [-namespace string]
         [-computerName string[]]
            [-credential PSCredential] [-list] [CommonParameters]

      Get-WmiObject [-class] string [[-property] string[]] [-namespace string]
          [-computerName string[]] [-filter string]
             [-credential PSCredential] [CommonParameters]

      Get-WmiObject -query string [-namespace string]
          [-computerName string[]]
             [-credential PSCredential] [CommonParameters]

Key
   -class string
       The name of a WMI class (see list below).

   -property string
       A WMI class property (or set of properties) to retrieve.

   -namespace string
       The WMI repository namespace.
       If you don't specify the -Namespace parameter, then root\CIMV2 
       will be used by default.

   -list 
       List the names of the WMI classes.

   -computerName string[]
       The computer(s) to run against.
       A NETBIOS name, an IP address, full domain name or local (.)
       WMI information is retrieved via the WMI Service (CIMOM)
       on the specified computers.

   -filter string
       A where clause to use as a filter. Use the syntax of the WQL language.
       Do not include the WHERE keyword.
	   
   -query string
       A WMI Query Language (WQL) statement to run. 
       Event queries are not supported.

   -credential PSCredential
       Use the specified credential to authenticate the user. Type a user name  
       or submit a credential object (created with Get-Credential)
       If you supply a user name, you will be prompted for a password.

CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

gwmi is an alias for Get-WmiObject

For WMI to work against a remote machine you may need to first configure it's local Windows firewall to allow the remote access.

When using -filter with a wildcard, use the WMI specific wildcards: % for zero or more characters, _ for a single character.

WMI Classes

The WMI classes available will vary according to your operating system.
List all WMI classes:
PS C:\> Get-WmiObject -List

Find a specific class:
PS C:\> Get-WmiObject -List | Where { $_.name -match 'User'}

Some common WMI classes:

Win32_computerSystem
Win32_bios
Win32_baseboard   (Motherboard)
Win32_processor   (32+64 bit processor info)
Win32_LogicalDisk  (hard disk)
Win32_PhysicalMemory
Win32_operatingSystem  (Virtual Memory)

List all properties of a class:
PS C:\> Get-WmiObject Win32_bios | Get-Member

Find a specific class property:

PS C:\> gwmi Win32_bios | Get-Member -MemberType property | Where { $_.name -match 'install'}

Examples

Display information about all processes:

PS C:\> gwmi win32_process

Display service names that starts with 'Oracle':

PS C:\> gwmi win32_service -filter "name like 'Oracle%'" | select name

Display services running on the machine 'Server64':

PS C:\> gwmi win32_service -computername Server64

passing username credentials:

PS C:\> gwmi win32_service -credential SS64\Simon -computer Server64

List services that are set to start automatically:

PS C:\> gwmi win32_service -filter "startmode='auto'" | select name,startmode

List services that are set to start automatically (same as above but written in WQL):

PS C:\> gwmi -query "select * from win32_service where startmode='auto'" | select name,startmode 

Display information about the Alerter service:

PS C:\> gwmi -query "select * from win32_service where name='alerter'"

Stop the Alerter service:

PS C:\> (gwmi win32_service -filter "name='alerter'").StopService()

Display svchost processes:

PS C:\> gwmi win32_process -filter "name='svchost.exe'" | select commandline, name

Display BIOS and Memory information:

PS C:\> gwmi win32_bios | format-list *
PS C:\> gwmi Win32_ComputerSystem
PS C:\> gwmi Win32_PhysicalMemory

"A good question is like a miniskirt. Long enough to cover the essentials, but short enough to keep everyone interested" - Charles Halsey

Related Powershell Commands:

Get-WmiObject Win32_OperatingSystem - Get the OS and service pack
Get-Credential - Get a security credential object based on a user name and password.
WQL (WMI Query Language) - msdn.microsoft.com



Back to the Top

© Copyright SS64.com 1999-2010
Some rights reserved