Tags


Powershell

And now we return to looking a little more into Powershell.

With these articles (or Howto’s however you’d like to think of it) we’re going to assume you know very little about Powershell and are just trying to fit all the pieces together.

Now a lot of you, like me, maybe had no clue what WMI was (or even care) or weren’t heavy into scripting to use it, or for that matter couldn’t tell WHERE to start in that pile.

This is not a deep dive lesson into WMI.   A quick rundown would be that WMI (Windows Management Interface) is a way to get a LOT of information about any computer in a Windows Environment, easily.

WMI objects contain everything from the current Operating system (whether Server or Workstation), patch Levels, CPU speed, type, free drive space, BIOS, manufacturer….

Well the list is huge and I won’t get too deep into it. 

But there’s a lot.

Powershell can natively talk to WMI.  Just like anything else in Powershell it’s very easy.  

First off, one of the things I felt I needed was a list of EVERYTHING available in WMI, even just to see if it had what I needed.

In Powershell just type

 

GET-WMIOBJECT –LIST

 

That command lists EVERY single WMI-OBJECT available.  Too many for a blog post.  But it’s easy to capture the output so you can dig and mine through the list.  Here are a couple of ways to get you going.

Method One.  Store in a CSV file so you can search with a Spreadsheet.

Run the “GET-WMIOBJECT –list” and pipe the output into “EXPORT-CSV” and create a Comma Separated Value file you can search through

 

GET-WMI-OBJECT | EXPORT-CSV C:LISTOFWMI.CSV

 

This will create a CSV or “Comma Separated Value” file called LISTOFWMI.CSV containing all the WMIObjects which can be searched with a spreadsheet (like Excel) or even a text editor (Although a spreadsheet is far easier!).  The nice part of the bulk of the objects have names that reflect the information they are carrying.  Like WIN32_BIOS which shows all the details about your computer manufacturer and even ServiceTag if it’s a Dell. or  WIN32_PHYSICALMEMORY which holds all the details (including slot position) of the physical memory sticks on your circuit board.

Method Two.  Query output and Pipe to “WHERE-OBJECT” commandlet to search on the fly

Another method that works very nicely if you have an idea of maybe a name or type of content is to run the output there a “WHERE-OBJECT” and pick off the content you want.   Once you understand how to compare information in Powershell, I find this one quite nice.

 

GET-WMIOBJECT | WHERE-OBJECT { $_.Name –like “*memory” }

 

Will produce a list of WMI Objects which only contain “memory” in their name.  Which could yield all sorts of useful information you can run a query on regularly about the memory.

And if THAT list is still too long, you can pipe all of THAT into the EXPORT-CSV Commandlet to give you a list you can sit down and examine.

 

GET-WMIOBJECT | WHERE-OBJECT { $_.Name –like “*memory” } | EXPORT-CSV C:MYSMALLWMI.CSV

 

So fantastic, we have a way to pull this information out of WMI so we have a useful list.  

Now what do we do with it?

That my friends, will be in our next posting.

 

Until Next time

Sean
The EnergizedTech

Advertisements