3

I am a linux guy so I'm used to "grep". With grep it keeps the columns, however in powershell it changes the output. For example:

Get-WmiObject -List | Select-String -Pattern "Win32_LogicalDisk$"

\\COMP\ROOT\cimv2:Win32_LogicalDisk

Where as "Get-WmiObject -List" puts out the columns such as:

  CIM_Tachometer                      {SetPowerState, R... {Accuracy, Availability, Caption, ConfigManagerErrorCode...

I would like my "Select" to yield the entire column as opposed to just the object or whatever it's returning. I would like to emulate a grep of the actual output of Get-WmiObject -List

Also as a bouns side question: Besides MSDN what is a good site that lists all the WMI objects and what they return? These seem like a super powerful way to get information about any aspect of a windows system. AmIRight?

linuxadmin
  • 51
  • 1
  • 1
  • 3
  • 2
    Yes you are right that WMI is a powerful way to get information about a Windows system, and it not only gives information, but also has methods that actually take actions too! – Ryan Ries Aug 15 '13 at 13:23

1 Answers1

3

You don't want to use Select-String. Powershell offers Where-Object cmdlet for this sort of filtering:

Get-WmiObject -List | Where-Object { $_.Name -eq "Win32_LogicalDisk" }

You may also use Select-Object to expand the property "Properties" on the object returned from Where-Object:

Get-WmiObject -List | Where-Object { $_.Name -eq "Win32_LogicalDisk" } | Select-Object -ExpandProperty Properties

If you want to explore WMI, there are many tools available. One Powershell version, WMI Explorer may be of particular interest to you.

jscott
  • 24,484
  • 8
  • 79
  • 100