Home > PowerShell > Accessing WMI Information From PowerShell

Accessing WMI Information From PowerShell

I’m starting to learn how powerful the Windows Management Instrumentation aka Windows WMI is. One of the simpliest ways I found of accessing the information is via Windows PowerShell. Here is a simple PowerShell command that will return the Win32_OperatingSystem information.

Get-WmiObject Win32_OperatingSystem

The following command returned the following on my Windows XP box, and yes, anywhere you see XXXXX I censored the data for my personal privacy…

SystemDirectory : C:\WINDOWS\system32
Organization    : XXXXX
BuildNumber     : 2600
RegisteredUser  : XXXXX
SerialNumber    : XXXXX-XXX-XXXXXXX-XXXXX
Version         : 5.1.2600

If we use a pipe command, we can return the information in a table

PS H:\powershell> Get-WmiObject Win32_OperatingSystem | format-table

SystemDirecto Organization  BuildNumber  RegisteredUs SerialNumber Version
ry                                       er
------------- ------------  -----------  ------------ ------------ -------
C:\WINDOWS... XXXXX...      2600         XXXXX...     XXXXX-XXX... 5.1.2600

Of course, what if we just wanted to return the Windows Version and not all of the miscellaneous/irrelevant data? We can pipe the Get-Member command to see all of the properties that are hidden in that class.

Get-WmiObject Win32_OperatingSystem | Get-Member

Running this command shows us a list of MemberType, if you see a MemberType of Property we can query to see what is contained within that property field by using the Format Table command “ft.” For example

PS H:\powershell> Get-WmiObject Win32_OperatingSystem | ft Version, ServicePackMajorVersion

Version                                                 ServicePackMajorVersion
-------                                                 -----------------------
5.1.2600                                                                      3

Now, what if we want to access information on a remote client or server? Simple! just concat the computer name to the WMI call. Just make sure to change “ComputerName” to the client/server name.

PS H:\powershell> Get-WmiObject Win32_OperatingSystem -computer "ComputerName" | ft Version, ServicePackMajorVersion

That’s great, but if you don’t have access to client/server under your normal Windows or AD credentials, we can authenticate as a different user. To do this we are going to assign our credentials to the variable $cred (short for credentials), you can change this name to whatever you want. Once we’ve logged in, we will pass those to the client or server that we are trying to authenticate against to login and view the WMI system info. When we call Get-Credential this causes a Windows popup asking us to login.

PS H:\powershell> $cred = Get-Credential

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

PS H:\powershell> Get-WmiObject Win32_OperatingSystem -computer dev-ghost -Credential $cred

SystemDirectory : C:\WINDOWS\system32
Organization    : XXXXX
BuildNumber     : 3790
RegisteredUser  : XXXXX
SerialNumber    : XXXXX-XXX-XXXXXXX-XXXXX
Version         : 5.2.3790
  1. August 14th, 2020 at 19:52 | #1

    Hello! This is my 1st comment here so I just wanted to give a quick shout
    out and say I really enjoy reading through your blog posts.
    Can you suggest any other blogs/websites/forums that cover the same topics?
    Appreciate it!

  1. January 31st, 2020 at 20:01 | #1
  2. February 4th, 2020 at 21:10 | #2
  3. March 11th, 2020 at 13:31 | #3
  4. March 13th, 2020 at 21:01 | #4
  5. March 13th, 2020 at 21:34 | #5
  6. March 14th, 2020 at 18:04 | #6
  7. March 16th, 2020 at 14:34 | #7
  8. March 16th, 2020 at 23:25 | #8
  9. March 17th, 2020 at 00:50 | #9
  10. March 17th, 2020 at 10:19 | #10
  11. March 18th, 2020 at 12:39 | #11
  12. March 19th, 2020 at 19:54 | #12