"Windows Management Instrumentation (WMI) is the primary management technology for Microsoft® Windows® operating systems. It enables consistent and uniform management, control, and monitoring of Windows computers. Based on industry standards, WMI allows us to query, change, and monitor configuration settings on desktop and server systems, applications, networks, and other components. We can write scripts that use the WMI Scripting Library to work with WMI and create a wide range of systems management and monitoring scripts."
Well, that's nice, but how to get around in this "WMI world" with PowerShell. It's not that hard at all.
How to know which WMI components are available:
get-wmiobject -list
Wow, this is a long list. Let's add a filter:
get-wmiobject -list | where {$_.Name -match "some_component_of_my_pc"}
This works! By the way, did you know you can use regular expressions with the "-match" command in PowerShell ? It's very cool! Another nice thing is that the command "get-wmiobject" can be abbreviated to "gwmi".
An example, I want to know more about the processor of my computer. So, I search for the "processor" keyword:
get-wmiobject -list | where {$_.Name -match "processor"}
and now I see win32_processor is available. So I use this command:
get-wmiobject win32_processor
and I get all kind of information about the processor in my computer. If you want to know which properties you can use (maybe for a script you want to write), you can use this command:
get-wmiobject win32_process | get-member
and you will see a list like this:
Handles
ProcessName
VM
WS
AttachDebugger
GetOwner
GetOwnerSid
SetPriority
Terminate
Caption
CommandLine
CreationClassName
CreationDate
CSCreationClassName
CSName
Description
ExecutablePath
ExecutionState
Handle
HandleCount
InstallDate
KernelModeTime
MaximumWorkingSetSize
MinimumWorkingSetSize
Name
OSCreationClassName
OSName
etc.
You can use the properties in scripts, for example:
...
(
(get-wmiobject win32_process | foreach {$_.osname}) -match "Windows XP")
{
write-host "Windows XP has been installed"
}
else
{
write-host "Windows XP has not been installed"
}
...
If I want to know more about the USB features of my computer, I can search like this:
get-wmiobject -list | where {$_.Name -match "usb"}
and now I see what's available for me:
CIM_USBController
Win32_USBController
CIM_USBDevice
CIM_USBHub
Win32_USBHub
Win32_USBControllerDevice
CIM_USBControllerHasHub
Win32_PerfFormattedData_usbhub_USB
Win32_PerfRawData_usbhub_USB
so, when I use:
get-wmiobject win32_usbcontroller
I know all about the USB controller of my computer.
Finding WMI information is really easy this way !
This is a nice one! I want to know which software is installed on my computer. There are multiple options for this:
You can search for the keyword "software":
get-wmiobject -list | where {$_.Name -match "software"}
and
get-wmiobject win32_softwarefeature
You can search for the keyword "product":
get-wmiobject -list | where {$_.Name -match "product"}
and
get-wmiobject win32_product
You will see long lists of software programs.
Wow, this is a long list again ! What I missed was path information. So, after some search on Google I found out this command is best to find installed software on your computer:
Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | foreach {get-itemproperty $_.psPath}
Recent Comments