Learn How to Create Custom Column Heads for PowerShell Out-GridView

One of my co-workers, who shall remain nameless (but it rhymes with Jalcolm Meffrey), asked a good question today-namely “How do I take this custom formatting from a “Format-Table” command and use it in the gridview control (Out-GridView). It took me a couple of minutes, but the internet bestowed her bounties upon me once again. And, no I’m not talking about going to the hoochie-mama sites.

I found this old posting from Ed Wilson, “The Scripting Guy”. Thank you Ed!

Learn How to Create Custom Column Heads for PowerShell Out-GridView – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs.

For those of you who won’t/can’t be bothered to read it, basically it boiled down to “Don’t use format-table, use select-object, and build your columns using the -f operator syntax”.

With some minor modifications, you turn this:

Get-CimInstance -ClassName Win32_LogicalDisk  |
Where-Object DriveType -eq 3 |
Format-Table @{n=’DriveLetter’;e={$PSItem.DeviceID}},
             @{n=’FreeSpace(GB)’;e={$PSItem.FreeSpace / 1GB};formatString=’N2′},
             @{n=’Size(GB)’;e={$PSItem.Size / 1GB};formatString=’N2′},
             @{n=’Type’;e={$PSItem.Description};width=5} -AutoSize

Into this:

Get-CimInstance -ClassName Win32_LogicalDisk  |
Where-Object DriveType -eq 3 |
Select-Object -Property @{Label=’DriveLetter’;Expression={$PSItem.DeviceID}},
    @{Label=’FreeSpace(GB)’;Expression={“{0:N2}” -f ($PSItem.FreeSpace / 1GB)}},
    @{Label=’Size(GB)’;Expression={“{0:N2}” -f ($PSItem.Size / 1GB)}},
    @{Label=’Type’;Expression={$PSItem.Description}} |  Sort-object ‘FreeSpace(GB)’ | Out-Gridview


If you were so inclined, you could swap out “Out-Gridview” for “Format-Table” or whichever output command you needed.

Thanks Jalcolm (if that is your real name) for giving me something to dig into and solve!


TechEd NZ 2013 Wrapup

I’ve been tweeting up a storm over the last few days, picked up a few more followers. Yay! The last two days of TechEd went by in a blur. Unfortunately I (and Malcolm) got to spend waaaaaaaayyyyyyyy too much time on the phone with Prometric support, trying to get their software to work properly, but that’s a story for another day . . .

When I wasn’t doing that I saw a couple of good Exchange sessions by Scott Schnoll. I would highly recommend watching any of the presentations he does. He really understands Exchange well, and has a great knack for making the complex clear. I learned a great deal. I sat in on a few sessions that were reminders of “what not to do” when presenting. Here’s a hint guys: it’s really obvious when you haven’t prepared and practiced your demos.

My employer, Auldhouse sold out all of our exams, we had several attendees earn new certifications. So it was very successful from our point of view.

But best of all I got to catch up with some old friends. It’s always nice to catch up w/ Miguel and Dandy and Lohit and others. I also made some new friends, and got to be part of a great panel discussion on why its important to keep your skills and certs up to date. Some really interesting stuff came out of that.

But now it is done, and I am knackered. Time to go home and see my family again. 🙂

Hopefully I’ll see some of you there next year, if not sooner.