Posts

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

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

Using ThinApp to Troubleshoot Misbehaving Applications

One of my customers had a challenge with a nonpersistent VDI pool.  They were using a web app that required some specialized software in order to work.  That specialized software installs per user, when the web app is executed.  On persistent desktops, it’s not too big of a deal, since the user installs it once and is good to go.  On the nonpersistent pool, it proved to be a pain point, as it was prompting to install every day for every user. After digging into it a bit, it turned out that the key to the install was a .cab file.  Extracting that file didn’t prove helpful, so I went another route.  If you buy VMware View, you get ThinApp along with it.  So, I ThinApped Internet Explorer and set it to WriteCopy isolation mode.  I stuck the executable onto a file share and created a ‘thinstall’ folder alongside it (so that the sandbox for that package would reside on the file share).  Once that was in place, I instructed one of the desktop ad...

PowerCLI Scripting to set Queue Full Threshold and Queue Full Sample Size

If you've ever dug into the guts of an ESXi host configuration, you've probably found that there are some settings that you just can't configure without the command line.  An example that I came across recently was for a customer with 3Par storage.  As per the VMware and 3Par Best Practices Guide , you should configure 3 settings on a per LUN basis: the Multipathing Policy, the Queue Full Threshold and the Queue Full Sample Size. The Multipathing Policy is easy to set through the GUI, at least if you really like clicking your mouse.  The Queue Full settings don't exist in the GUI though; to get at them, you must use the command line.  The 3Par guide helpfully provides the ESXCLI command that you need in order to configure those LUNs: esxcli storage core device set --device <canonical name> --queue-full-sample-size 32 --queue-full-threshold 4 So, just run that command on every LUN, from the command line on every Host in your environment.  Yeah, ri...

Configuring PowerShell for Server Administration

Like so many others, I’ve recently been learning just how powerful and useful Microsoft’s PowerShell can be.  One of its best attributes is how extensible it is.  There are a ton of 3rd party plugins and modules that allow you do to amazing things, very easily.  As I use the tool more and more, I’ve found a core set of extensions that are vital for my daily work.  Besides that, there’s some client side configuration that I do in order to automatically load those modules and snapins when I start PowerShell.  Admittedly, it does make the PowerShell window take a little bit longer to open, but when I’m using those tools 90%+ of the time, I figure that it’s better to just grab them by default.  So, here is how I like to configure my administrative workstation’s PowerShell. The first thing that I do is upgrade to PowerShell 3.0.  Microsoft has PowerShell 3.0 Installation Instructions available; make sure that you follow them.  If you don’t have the ...

PowerShell Tips: LDAP String Manipulation and why not to use Trim

I've been working with PowerShell a lot recently and stumbled a little bit with String Manipulation.  So, I've decided to post some details of what I've learned, to hopefully help others avoid my mistakes. String manipulation can be very important when scripting, especially if the purpose of the script is to output a human readable report.  First, there's a great TechNet article on string manipulation in PowerShell .  It covers the basics in great detail; my intent is to supplement that article with some of the pain points that I came across while using those techniques. How to Trim a String Trimming a string simply means removing characters from the ends of that string.   There are 3 Trim commands: .Trim() .TrimStart() and .TrimEnd().  As the names imply, TrimStart() removes characters from the start of a string, TrimEnd() removes characters from the end of a string, and Trim() removes characters from both ends of the string.  Those Trim commands ar...

Improved Desktop Restart Script

I've done some work lately to improve my desktop restart script from earlier in the month. I've made a few important changes - now the script will wait (by default 10 seconds) between restart commands so as to not overwhelm the environment. That wait time is a configurable parameter; just invoke the script with the -wait # option to set it to wait for that number of seconds. This is especially useful for nonpersistent pools, as you can pass it a highish number (such as 45 seconds) in order to ensure that the bulk of the desktops in a floating pool remain available at any one time. I've also improved the script's session handling logic. It will now restart systems with Disconnected sessions (but will still not restart desktops with Connected sessions). It is also no longer sensitive to the domain suffix of the desktops. Finally, I found a condition where it would fail to issue a hard reset for a frozen desktop, if that desktop was so frozen that the VMTools compl...