Posts

Showing posts from January, 2014

PowerShell Select-Object Details

Select-Object is a very powerful tool for any PowerShell user.  Many PowerShell cmdlets return a LOT of information when executed.  Select-Object makes it really easy to reduce the noise and only display those fields that are meaningful.  See below:

$events = get-eventlog system –newest 25
$events | select TimeGenerated,EntryType,Message


The first command will store the most recent 25 entries from your system log in a variable called $events.  The second command prints the contents of that variable, selecting only the TimeGenerated, EntryType and Message columns (you might want to pipe all of that into FL in order to make it more readable).

Ok, so that’s made it easy for us to filter the results that get displayed on screen, but that’s not usually the problem with event logs (or at least, not the main problem).  When you’re troubleshooting a problem, you probably want to filter the results to only show errors and warnings, then just display the relevant fields.  Where-Object to the re…

PowerShell Select User Specified Rows with Where-Object

The more I learn about PowerShell, the more I come to love the Where-Object and Select-Object commandlets.  Those two commands make life so much easier, especially when dealing with large data sets.  I've been working on just such a script lately and, in an effort to make it easier for other people to use, I've decided that I want to make the output table (which is going into an HTML file) user definable.  By using Where-Object and Select-Object, I can accomplish exactly this, although there was a bit of a learning curve.

In this post, I'm going to discuss Where-Object.  Where-Object allows us to select rows from the source material.  I took the user's input into a variable and simply used that in my Where-Object structure.  Let's look at an example!  First, let's prepare an object to be manipulated with the following code:

$myList = get-eventlog system -newest 15

That command will populate the $myList variable with the latest 15 entries from your system log, w…