PowerShell: Programming with Hand Grenades

“PowerShell is great because I am flawed “- Jeffrey Snover

I’m a big fan of PowerShell: every-time there’s a problem I need to fix, I think “how can PowerShell help me here?” Back in July there was a great Session on the Microsoft Virtual Academy called “Getting Started with PowerShell”. It was hosted by Senior Technologist at Microsoft Jason Helmick and Distinguished Engineer and the Lead Architect for the Windows Server Division. Snover is the inventor of Windows PowerShell so to have a free 8 hour session on PowerShell by the guy that wrote the thing was an opportunity not to be missed. It was a cross between a gentle canter and a deep dive. It was broadcast on the 18th of July 2013. Typically videos are available to download roughly 2 weeks after the initial broadcast, so it should be available now. Regardless of your experience of PowerShell I’d recommend a watch of this.

I’ve got a lot of time for Jeffrey Snover. Last year at TechEd 2012 I sat in on his Q&A. He speaks with a lot of common sense; his blog On Heroes highlights this sort of sensibility.

In the broadcast, Jeffrey explained the principles he had in mind when designing PowerShell. The naming of cmdlets was standardized to verb-noun, and therefore all cmdlets have a regular, self describing naming convention. There are a list of permitted verb, so that cmdlets are schema-ised (type get-verb to list of permitted verbs). Jeffrey explained that he didn’t want to have to memorize all the cmdlets, and so aliases were born. He also explained about the Get-Help cmdlet, which I’m going to delve into here.

Entering get-help in a PowerShell lists the help topics and how to use the Get-Help cmdlet.

2013-09-04 10_27_11-redPhoenixGet-Help gets the help content that it displays from help files on your computer. Without the help files, Get-Help displays only basic information about commands. Some Windows PowerShell modules come with help files. However, beginning in Windows PowerShell 3.0, the modules that come with Windows do not include help files. To download or update the help files for a module in Windows PowerShell 3.0, use the Update-Help cmdlet. Running Update-Help will download the PowerShell help onto your computer. In fact if you ran Get-Help Update-Help you’ll get info on the Update-Help cmdlet.

2013-09-04 10_28_27-PRE2SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2I’m going to run Update-Help to download the latest help topics onto my computer. Depending on how much you need to download, and how good your internet connection is, this can take some time. Don’t forget to read the get-help update-help topic as it’ll tell you that you need to start PowerShell with the “Run As Administrator” option or else you won’t be able to download the help files.

2013-09-04 10_29_52-PRE2SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2Now that you’ve got the latest help downloaded you can get the help topic on any cmdlet you need, like write-host.

2013-09-04 10_44_06-PRE2SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2You can also view the help topics for Windows PowerShell online in the TechNet Library. To get the online version of a help topic, use the Online parameter, such as: Get-Help Get-Process -Online. This opens up a webpage with the help. You might notice that the info given on the webpage appears to be more than simply running get-help. If you don’t want to have to go online to get this level of info you can run Get-Help -detailed to get the same info.

2013-09-04 11_48_44-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2It’s a fantastic level of info here, and scrolling down to the bottom there are examples of the cmdlet. If you’d rather just see the examples then you can run Get-Help Get-Help -examples.

2013-09-04 11_50_58-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2What I like about the examples is that they’ve worked really hard on allowing you to explore and expand your own knowledge. One example shows us that some features have help articles that begin with “about_”, such as “about_signing” which you will need to know about if you want to run your own modules or scripts on a machine. But if you don’t know what topics have “about_” articles, how can you know what they are? The example show us that f you enter “get-help about _*” then you get the whole list of topics that have “about_” articles.

2013-09-04 15_44_13-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2Now I’ve got the list of all the about articles available. Running “get-help about_signing” returns the entire help article.

2013-09-04 15_50_59-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2Getting the example is this way is a new feature in PowerShell 3. But my favourite new feature of PowerShell 3 is the parameter”-showwindow”. It opens up the help in a completely separate window, not a PowerShell console.

2013-09-04 11_57_47-Get-Help HelpAnd the great thing about this window is that it has some really cool features like highlight find with previous and next buttons:

2013-09-04 12_25_28-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2a zoom in function:

2013-09-04 12_26_19-Get-Help HelpAnd even a settings window to help you get to the subsection of the help topic:

2013-09-04 12_27_28-PRE1SQL01.PROD.INFRA.INT - Remote Desktop Connection Manager v2The whole concept of offline help that can be accessed like it was on the MSDN site is by far a great addition to PowerShell 3.0.

There’s a whole heap of features for PowerShell beyond the built in cmdlets or scripts that you can write, and this is just a small subset of what you can do. I highly recommend watching the PowerShell video.

Author: Richie Lee

Full time computer guy, part time runner. Full time Dad, part time blogger. Knows a thing or two about Pokémon. Knows too much about SQL Agent. Writer of fractured sentences. Maker of the best damn macaroni cheese you've ever tasted.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s