Grep, Select-String, Windows Powershell and You

For any of you that come from a Linux or Unix background, you probably have a good solid friendship with the grep command. Unfortunately, the utility of this little command has been overlooked for many who spend the majority of their day in the Windows world. This caused me a bit of grief when I went looking for the equivalent command in PowerShell. Now, don’t get me wrong, I found the Select-String command pretty quickly, and I had great success when searching inside of files, but for searching the output of a powershell command, I found its results to be somewhat…

C:\> ls | select-string "Windows"

install.exe:57:♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLM NOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ =   GetProcessWindowStation
GetUserObjectInformationA   GetLastActivePopup  GetActiveWindow MessageBoxA USE R32.DLL  ( n u l l )     (null)      ♠  ♠ ☺  ► ♥♠ ♠☻►♦EEE♣♣♣♣♣50 P    (
8P 700WP     `h````  xp       ♠������  ►♥�����¶♣
♣EEE���♣  00�P� ('8PW�  700PP�    (����   `h`hxp
Complete Object Locator'    Class Hierarchy Descriptor'     Base Class
Array'   Base Class Descriptor at (  Type Descriptor'   `local static thread
guard' `managed vector copy constructor iterator'  `vector vbase copy...

…less than useful (As a side note, I found it difficult to include the many system beeps that resulted from this command, so you’re have to live with just the truncated text output).

Those of you who have an intimate knowledge of PowerShell can probably tell pretty quickly what happened there. Instead of searching the text of the output of ls, Select-String was fed a bunch of FileInfo and DirectoryInfo objects, which it was very happy to read into memory and attempt to cat to the terminal.

I tried getting around this issue recently by piping everything to Out-String, first, but I was left with more unexpected behavior:

C:\> ls | Out-String | Select-String "Windows"

    Directory: C:\

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        10/14/2014  11:19 AM            altools
d----        11/10/2014   3:52 PM            DFSReports
d----        10/29/2014  10:07 AM            ExchangeSetupLogs
d----         11/5/2014  11:43 AM            inetpub
d----        11/18/2014   4:21 PM            temp
d-r--         11/6/2014  12:23 PM            Users
d----        11/14/2014  11:09 AM            Windows


Yay, we got the string output from the previous command! Unfortunately, for some reason, Select-String was unable to filter it. Oh, and no, I haven’t figured out the cause. I have, however, found the solution. Checking the help file reveals that Out-String has a nifty little switch named Stream, which changes the way the output hits the pipeline. Using this switch appears to give us the expected result:

C:\> ls | Out-String -Stream | Select-String "Windows"

d----        11/14/2014  11:09 AM            Windows

So, there it is. I realize this is a bit of a long-winded article for such a simple thing, but sometimes it’s useful to have a bit of context. Hopefully that’s the case here, and I’m not just completely full of hot air.

As a side note, Windows PowerShell has some pretty fantastic filtering capabilities which Don Jones at Microsoft wrote a very helpful article about. If you find yourself using Out-Host -Stream | Select-String in a script, you’re probably doing it wrong.

Trouble changing passwords in OWA? Check your minimum password age policy.

I recently ran into an issue at work where users were having some difficulty changing their passwords via OWA. We just rolled out Exchange and are setting new users up, so it’s pretty important that they be able to reset their passwords after initial setup.

It turns out that OWA can have some difficulty with the Minimum Password Age policy on domain controllers. By default, this is set to one day. Users attempting to change their passwords on the same day that their Exchange accounts were created will be greeted with an error stating “The password supplied does not meet the minimum security requirements. Please contact technical support for your organization if you need help.”

You can read a bit more about the issue in the links below:

Unmet Prerequisites When Installing Active Directory Management Gateway

Earlier today I was attempting to install the Active Directory Management Gateway service on a new Server 2003 domain controller and I was rewarded with an error stating:

Setup cannot continue because one or more prerequisites
required to install KB968934 failed.

Oh, what fun. Fortunately for me, some kind folks over at Microsoft’s Technet forums had the answer. There are two hotfixes that need to be installed on a Server 2003 SP2 machine before the AD Management Gateway Service can be installed:

I found that downloading these can be a pain. KB969166 requires a Microsoft download manager and KB969429 will only show a 64-bit download if you’re on a 64-bit machine. You must download it from a 32-bit machine if you’re applying it to a 32-bit server. Also, be prepared to restart your server for KB969429.

Groupwise 7 client crashes on Server 2008 R2

I recently ran into an issue with the GroupWise 7 client crashing on a new terminal server running Server 2008 R2. The error I received was “This application has requested the Runtime to terminate it in an unusual way.”

Some searching through Novell’s site revealed that this is a known issue with the GroupWise client not playing well with DEP. Sure enough, adding an exception for the GroupWise client in the DEP configuration resolved the issue. For those who are unsure how to do this:

  1. Right-click on Computer and select Properties.
  2. Click the Advanced System Settings link.
  3. Click the Advanced tab.
  4. Click the Settings button under the Performance section.
  5. Click the Data Execution Prevention tab.
  6. Click the Add button under the exceptions list.
  7. Navigate to the grpwise.exe executable and click the Open button.
  8. Click the OK button on each dialog to save your changes.

“VpxClient has encountered a user-defined breakpoint.”

Earlier today I was trying to download a VM from one of our ESX datastores using the Datastore Browser. Unfortunately, the vSphere Client kept crashing with the error “VpxClient has encountered a user-defined breakpoint” after I chose the destination folder. Some quick research turned up a thread on the VMware Community site which highlights the cause: Datastore browser – user-defined breakpoint

…If you close the VI Client and re-open it as administrator the problem appears to go away…

It appears that VMware is not fully finished preparing the vSphere client for UAC elevation, which is pretty sad, considering Vista shipped with UAC over four and a half years ago. It’s unfortunate to see a company as forward thinking as VMware let their client stagnate so much.

Implementing IPv6 at home—part 2

A while back I did some experimentation with IPv6 on my Cisco 2611xm. I was using a tunnel provided by Hurricane Electric, which worked well, but I had no firewall and that made me a bit nervous. A little while after I got things set up, I procured a Cisco ASA5505 with a 50 client license via eBay. My hope was that I could use the ASA for the firewall and the router to terminate the tunnel. As it turns out, this would have required a second IP address, because the ASA is not able to pass Protocol 41 traffic.

Continue reading

Upgrading to vSphere Part 2: Hosts and VMs

In my last post I described my experience with upgrading from VirtualCenter 2.5 to vCenter4. Here I’ll be describing the process of upgrading the host machines via a couple of different methods as well as my process for getting the VMs upgraded to the latest verision of VMware’s virtual hardware.

Continue reading

Upgrading to vSphere Part 1: Installing vCenter

Last week I started our migration from VMWare’s VI3 to vSphere. There are many improvements to the load balancing capabilities as well as the management capabilities. The storage engine has been greatly improved as well. Storage vMotion is available in the GUI without a plugin and thin provisioning is finally available, which is a huge boon and reason enough to make the move on its own. Most of this process can be completed with no downtime for the virtual machines.

Continue reading

Formatting byte values in Excel 2007

I was given a project, recently, that involved creating a spreadsheet to list storage capacities and free space. One thing I wasn’t sure of, was how to format the values.

A bit of searching on the internet for formatting KB MB, etc. came up with a post by Ajay on which suggested pasting the following code into the current worksheet’s private module:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C:C")) Is Nothing Then
        If Target.Value < 1000 Then
            Target.NumberFormat = "0 B"
        ElseIf Target.Value < 999500 Then
            Target.NumberFormat = "0.000, KB"
        ElseIf Target.Value < 999500000 Then
            Target.NumberFormat = "0.000,, MB"
        ElseIf Target.Value < 999500000000# Then
            Target.NumberFormat = "0.000,,, GB"
            Target.NumberFormat = "0.000,,,, TB"
        End If
    End If
End Sub

I had some trouble with the macro and eventually abandoned it, but it did give me some ideas. The actual formats were good and I ended up using them later. The criteria for setting the formatting was spot on as well. After thinking about it for a while, I decided to look into Excel’s conditional formatting feature. There are premade rules for changing the cell color, etc., but it turns out that it’s capable of quite a bit more.

Continue reading

Remote server administration with Windows Vista

If you’re a systems administrator and run Vista, you might have run into some trouble with the server 2003 administration tools package (adminpack). Well, there’s good news for you. Remote administration is now built into the Vista operating system.

  1. Firstly, you should be running service pack 1. I believe the tools are available for the original release of Vista, but I haven’t delved into it.
  2. You’ll need to download the updated RSAT pack from Microsoft:

  3. Go to the control panel and open “Programs and Features”.
  4. Click on “Turn Windows features on or off.
  5. Find and enable “Remote Server Administration Tools”.

Once you hit OK, your system will spend about 5-10 minutes configuring itself for remote administration and the “Administrative Tools” menu should be populated.