Posts

Showing posts with the label String Comparison

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 ...