Sunday, February 28, 2010

Discovery In PowerShell – Get-Help vs. Get-Command

Discovery is process by which a user will learn to use any product. The more discoverable any product is, the easier it is for new users to get started. A disoverable product enables any user both to leverage what they already know and to find more. PowerShell was designed to be, and I believe is, a discoverable product.

One example of this came up this week – looking at how you can find cmdlets (and other stuff) that you can run. By using Get-Help, Get-Command and some where clause foo, you can quickly locate and learn about cmdlets in your environment. And, this help information provides examples to illustrate the use of a particular cmdlet and some products (eg SCVMM) add additional About_* files.

Get-Command and Get-Help are similar but different. They both can be used to find cmdlets and other help information. So while sharing a similar usage, they return different information. Get-Help returns information on 4 categories: Alias, Cmdlet, Provider and HelpFile. Get-Command, on the other hand, returns information of 6 different command types: Alias, Application, Function, Cmdlet, ExternalScript and Filter.

Where this helps is knowing which cmdlet to use to search for what. If you are using pure PowerShell Cmdlets, modules and scripts, Get-Help will be your main discovery tool. But if you are also using console applications from, say earlier versions of SharePoint, then Get-Command will help to find the commands you might need.

The trick to getting the most out of these cmdlets is knowing how to search and the key to that is using wildcards. If you want to find out what cmdlets, etc, are available for a PSSession object,

 

PSH [C:\]: Get-Help *PSSEssion*

Name                              Category  Synopsis
----                              --------  --------
Register-PSSessionConfiguration   Cmdlet    Creates and registers a new session configuration.
Unregister-PSSessionConfiguration Cmdlet    Deletes registered session configurations from the computer.
Get-PSSessionConfiguration        Cmdlet    Gets the registered session configurations on the computer.
Set-PSSessionConfiguration        Cmdlet    Changes the properties of a registered session configuration.
Enable-PSSessionConfiguration     Cmdlet    Enables the session configurations on the local computer.
Disable-PSSessionConfiguration    Cmdlet    Denies access to the session configurations on the local computer.
New-PSSession                     Cmdlet    Creates a persistent connection to a local or remote computer.
Get-PSSession                     Cmdlet    Gets the Windows PowerShell sessions (PSSessions) in the current session.
Remove-PSSession                  Cmdlet    Closes one or more Windows PowerShell sessions (PSSessions).
Enter-PSSession                   Cmdlet    Starts an interactive session with a remote computer.
Exit-PSSession                    Cmdlet    Ends an interactive session with a remote computer.
New-PSSessionOption               Cmdlet    Creates an object that contains advanced options for a PSSession.
Export-PSSession                  Cmdlet    Imports commands from another session and saves them in a Windows PowerS...
Import-PSSession                  Cmdlet    Imports commands from another session into the current session.
about_pssessions                  HelpFile  Describes Windows PowerShell sessions (PSSessions) and explains how to
about_pssession_details           HelpFile  Provides detailed information about Windows PowerShell sessions and the

Or try the following:

PSH [C:\]: get-command *PSSession*

CommandType     Name                                                Definition
-----------     ----                                                ----------
Cmdlet          Disable-PSSessionConfiguration                      Disable-PSSessionConfiguration [[-Name] <String[...
Cmdlet          Enable-PSSessionConfiguration                       Enable-PSSessionConfiguration [[-Name] <String[]...
Cmdlet          Enter-PSSession                                     Enter-PSSession [-ComputerName] <String> [-Crede...
Cmdlet          Exit-PSSession                                      Exit-PSSession [-Verbose] [-Debug] [-ErrorAction...
Cmdlet          Export-PSSession                                    Export-PSSession [-Session] <PSSession> [-Output...
Cmdlet          Get-PSSession                                       Get-PSSession [[-ComputerName] <String[]>] [-Ver...
Cmdlet          Get-PSSessionConfiguration                          Get-PSSessionConfiguration [[-Name] <String[]>] ...
Cmdlet          Import-PSSession                                    Import-PSSession [-Session] <PSSession> [[-Comma...
Cmdlet          New-PSSession                                       New-PSSession [[-ComputerName] <String[]>] [-Cre...
Cmdlet          New-PSSessionOption                                 New-PSSessionOption [-MaximumRedirection <Int32>...
Cmdlet          Register-PSSessionConfiguration                     Register-PSSessionConfiguration [-Name] <String>...
Cmdlet          Remove-PSSession                                    Remove-PSSession [-Id] <Int32[]> [-Verbose] [-De...
Cmdlet          Set-PSSessionConfiguration                          Set-PSSessionConfiguration [-Name] <String> [-Ap...
Cmdlet          Unregister-PSSessionConfiguration                   Unregister-PSSessionConfiguration [-Name] <Strin...

If you are looking for more conceptual information about some feature (typically the noun in the cmdlet name – as here “PSSession”) Get-Help will return the ‘About_’ topics, These help you to learn more about the underlying objects, as well as the help information about specific cmdlets. I personally use Get-Help to remind myself of the cmdlets names and spellings.

And finally – if you are using Get-Help on your local machine, you can usually specify the –online parameter. This opens up a browser window into Technet, pointing to the current documentation. If you look at the online help for Enter-PSSession (http://technet.microsoft.com/en-us/library/dd315384.aspx), you can see this page was updated mid December. The PowerShell writers do a fantastic job of fixing the online versions of the help. And they are working on a way to get these updates to you as fast as possible.

Saturday, February 27, 2010

PowerShell Master Class in Stockholm – Filling Up Quickly!

In a recent blog post, I mentioned the PowerShell Master Class I am running in Stockholm on March 9-11 2010 (see Http://Www.PowerShellMasterClass.Com for more details). I’m pleased to say the class is nearly full! I am looking forward to three great days with PowerShell!

NITkon – Day Of PowerShell in Norway

For those in or around Norway next month (well Wednesday March 17th to be precise), NITKon, a Norwegian education conference for IT Pros in Norway, is holding Deep Dive PowerShell – a full day Of PowerShell content. I think this is the first conference to hold a full day just on PowerShell!

The contents of the day look pretty good too:

  • PowerShell Modules – Bruce Payette (superstar member of the development team and outstanding author)
  • Proxy Functions – Dmitry Sotnikov (fellow MVP and the brains behind PowerGui)
  • PowerShell and Wmi – ME!
  • PowerShell and .NET/COM objects – ME again
  • Advanced Features in PowerGui – Dmitry Sotnikov
  • PowerShell Advanced Techniques – Bruce Payette

I can’t wait for this event. I’m always keen to see Bruce and Dmitry – they are awesome speakers. I hope we will be able to post the slides once the event is complete.

Hope to see you there.

Technorati Tags: ,

Tuesday, February 09, 2010

Formatting with PowerShell

PowerShell is an increasingly important tool for the IT Admin. In it’s early version, it didn’t do much, but with products like Exchange, SharePoint 2010, and System Centre being so PowerShell focused, it’s a tool every IT Admin needs to learn and learn how to leverage.

A key aspect of PowerShell is output – getting the output you need. In some cases, that output can be quick and dirty: how many mail boxes are currently on Mailbox-Server-1? Or how many handles has the DNS server used (and has that changed since last week).

But often, output needs to look good as well as being accurate. PowerShell has a wealth of formatting capabilities (and with 3rd party tools like PowerGadgets, you have a bunch more).

I’ve written a two part article for The Scripting Guys to explain some of these options. You can find Part 1 at: http://tinyurl.com/yhmvvul, and Part 2 at: http://tinyurl.com/ykt7wq6.

These articles are the basis for one of the modules in my upcoming PowerShell Master Class that I blogged about last week.  I’ve taken Module 3 of the class and turned it into these articles, although I’ll be adding some more stuff into the Master Class!

I’d be grateful for comments!

Sunday, February 07, 2010

Solarwinds – Free WMI Monitor

I am slowly pulling together my upcoming PowerShell Master Class. One of the modules looks at WMI objects and I’ve been searching for as many cool tools etc as I can find. Thanks to a couple of tweets (Shay and Doug!), I found a pretty cool free tool from Solarwinds, called WMI Monitor. This is a free download that does a number of things, including:

  • monitors the performance on a Windows server
  • leverages pre-built and community generated application templates for monitoring virtually any application
  • enables you to modify or design your own application templates with the built-in WMI browser

This tool is free, but you do have to register. Also – it’s a 60mb download! But if you are doing WMI scripting with PowerShell, it might well be worth the download.

Technorati Tags: ,,