San Diego 2012 PowerShell Deep Dive Slides and Demos

Last week at the PowerShell Deep Dive in San Diego, I did a short presentation on integrating Microsoft Office applications like Excel and Word with Windows PowerShell. I easily could have spoken much longer and probably tried to cram too much in. I spent a lot of time with my demos. I expect at some point a video of my talk will be posted on the TEC site. In the mean time you can download a PDF of my slide deck and a zip file with all of my demos. Some of the scripts have been revised slightly since my presentation. The scripts are NOT intended for production use. They are demonstration and proof-of-concept scripts. Many of them have hard coded paths for additional files so read them carefully before you try to run. I’ve tried to comment extensively so you can understand what is going on, but this is admittedly a complicated topic. I’m hoping to create some additional videos around these demos, but if you have questions please post a comment.

Enjoy.

On the Road Again

It’s that time of year again: conferences! I’ll be out and about a few places in the next few months and I hope our paths will cross. Here’s a short summary of where I’ll be speaking and when. If you are interested in having me speak for your group or perhaps you are interested in some private training or mentoring, please feel free to contact me.

First up is the PowerShell Deep Dive which is part of The Experts Conference April 29-May 2nd in always sunny and beautiful San Diego. I will be doing a session on integrating Microsoft Office into PowerShell. This will be an extension of some of the articles I’ve done recently for the Petri IT Knowledgebase on creating Word documents and Excel spreadsheets from PowerShell. I have discovered some new techniques that I’m excited to share.

On Saturday, May 12 I’ll be presenting several sessions at the SQL Saturday event in Rochester, NY. I’ll be doing sessions on background jobs, jobs and tasks in PowerShell 3.0 and one on PowerShell 3.0 workflows. I’m looking forward to this event because it is in my own backyard and the SQL Saturday folks are a new group for me. Should be a lot of fun.

Finally, I will be at TechEd in Orlando the week of June 11th. I have a session that I’m co-presenting with Group Policy MVP Jeremy Moskowitz. We’ll be talking about Group Policy Reporting and Analysis with Windows PowerShell. The focus is on what sort of things you want to look for in Group Policy that might give you problems and how you can find this information using PowerShell. I think Jeremy and I are going to have a lot of fun with this. The rest of the time at TechEd you’ll most likely find me wandering the expo hall or hanging out with the Scripting Guys. If more formal events are scheduled for me I’ll be sure to post the information and tweet about it. You do follow me on Twitter, right?

As far as I know there is still time to register for all of these events. I hope you’ll find time to sit in on one of my talks or at least come up and say hi.

Convert Text to Object

Today I have another tool in my new battle regarding turning command line tools into PowerShell tools. The bottom line is we want to have objects written to the pipeline. At the PowerShell Deep Dive in Frankfurt there was a suggestion about providing tools to help with the transformation from CLI to PowerShell and this is one of the items I came up with.

Many command line tools write output in a structured format. For example run this command:

There’s an “object” staring at us for each task. As an aside, don’t focus on the command line tool I’m using, pay attention to the technique. To turn output like this into ah object we simply need to split each line at the colon. The first index of the array will be the “property” name and the second index is the value. Here’s the function I pulled together.

The function processes each incoming line of text and splits it on the delimiter. The default is the colon since many CLI tools seem to use it.

Since I prefer property names without spaces I remove them from index 0 of the array. I’ve also found it helpful to trim everything to eliminate extra white space.

Each line is then added to a hash table.

When the hash table is complete it is used to create a new object.

The other “trick” I added is to group lines into an object. This let’s me take say every 5 lines of text and make that a single object. I create a counter and increment it whenever a line is processed. When the counter meets the limit, the object is created, the hash table is cleared and the process repeats.

Now I can run a command like this:

The output looks similar but now I have objects so I can take advantage of PowerShell. Here are some examples:

This is by no means perfect but I’d like to think it is a good start. For example, one downside is that all properties are strings where it would be nicer to have properties of an appropriate type. Still, I hope you’ll try this out and let me know what you think.

Download Convert-TexttoObject

Update
A newer version of the script can be found at http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/

Turning CLI Tools into PowerShell Tools Deep Dive Demos

Last week I did a presentation at the PowerShell Deep Dive in Frankfurt about turning command line tools into PowerShell tools. A video recording should be posted later. But in the meantime, here is a copy of my slide deck, in PDF and a zip file with my demos and scripts. I have some followup posts I’ll publish later.

The bottom line is that with not much effort and some basic PowerShell knowledge you can turn any command line tool into a PowerShell tool that writes objects to the pipeline. For example, I can take the NBTSTAT -n command:

and turn it into a PowerShell command:

The simple function is included in the zip file.

Download the Turn Command Line Tools into PowerShell Tools presentation and the CLI-to-PSH-Demos.

Deep Dive Formatting and Type Extensions

At the PowerShell Deep Dive, I did a short presentation on using format and type extensions. There was a lot of demo crunched into a very short period of time. Needless to say this is a complex topic that we could spend a lot of time on. But for now, let me share my slide deck and demo scripts. Continue reading “Deep Dive Formatting and Type Extensions”