PowerShell 2.0 is a nearly perfect management tool for administrators to use to manage their environments. Notice I said nearly perfect? Let me show you what I mean.
PS C:\> get-help
Get-Help is one of my favorite cmdlets of all time because it has discoverability capability built in. In this case, if you know the name of the cmdlet that you need some help on – like Get-Service – It’ll give you the Help for that cmdlet.
PS C:\> get-help get-service
But what if you don’t know the cmdlet you’re looking for? Here’s where the power of Get-Help is really amazing as it supports wildcard characters.
For examplem let's use *service*. Show all of the cmdlets that work with Services:
PS C:\> get-help *service*
Get-Help will search the entire help system (Similar to Bing or Google) to locate just what you need. In this case it will display a list of cmdlets that will let you work with services.
Get-Help searches the help system.
Once you have the list, look at the synopsis and find the cmdlet that does what you’re looking for.
You get the idea: search for a cmdlet, then use Get-Help to display the help of the cmdlet – Rinse and Repeat as needed.
PS C:\> get-help stop-service
The problem with Get-Help is PwoerShell V2.0 is that it can only search the help for cmdlets that have been imported into the system. Let’s say you wanted to find the cmdlets that will manage an IIS web server.
PS C:\> get-help *web*
This doesn’t return a list of web administration cmdlets, although it does return a cmdlet, its not the right one
If you’ve been working with PowerShell 2.0 for a while, you know that product-specific cmdlets are put into modules. In order to get to those cmdlets, you must first load those modules.
PS C:\ Import-Module WebAdministration
PS C:\ Get-Help *web*
PS C:\> get-module
Notice, I don’t have any modules loaded.
Therefore, we’ll run Get-Module again, and this time, PowerShell will return all of the modules that are currently available if we use ListAvailable:
PS C:\> get-module – ListAvailable
Notice at the bottom there’s WebAdministration module. That’s because we have IIS on this machine. But we don’t have access to discover the cmdlets. First we’ll need to import the module by using Import-Module web*.
PS C:\> import-module web*
The module’s in now imported and now we can use Get-Help * web * for this module.
PS C:\> get-help *web*
Don’t forget to import the module first before attempting to use Get-Help discoverability
Here is the problem. You can’t discover product specific cmdlets until you import the module for the product. What if you don’t know the name of the module? What if you have 50, 60, or 80 modules?
This is why you want to install PowerShell V3 on your servers and clients as soon as it releases.
I think this is one of the greatest feature updates for this release. PowerShell V3 can look at cmdlet names inside of modules regardless if they have been imported or not.
Read that statement again, you DO NOT need to import modules to discover the cmdlets that they contain. And that is a good thing as I think Microsoft is putting in up to 80 new modules in Server 2012.
Here is an example and I’m not going to import the web administration module first,
PS C:\> Get-Help *web*
Take a look at Figure 4 and you will notice Get-Help discovered everything I need.
PS C:\ get-help *service*
PowerShell v3 returns a list of cmdlets for services, just as you would expect.
Windows Server 2012 comes with more PowerShell modules than previous versions.
PS C:\> Get-Module -ListAvailable
This is where the new feature truly takes effect. If this was PowerShell 2.0, you would have to learn and remember what modules you wanted to have loaded, in order to be able to even find the cmdlets you were looking for.
Next let’s type Get-Help to find out what cmdlets are available to manage a website.
PS C:\> get-help *web*
Now in PowerShell 2.0, this would fail but in v3 we get all of the available cmdlets.
Additionally, V3 returns not only the list of cmdlets available, but also the module it’s coming from.
Using Get-Help no longer requires you to import the module first in PowerShell V3.0
PS C:\> get-help get-website
Not only can I discover the names of the cmdlets, I can get a full help listing of the cmdlets without ever importing the module.
Using Get-Help without importing the module
Last but certainly not least; you can execute the cmdlet without importing the module. Yup, that’s right boys and girls, the modules will be dynamically loaded.
This means that admins don’t have to go around memorizing modules, remembering to import everything before they use Get-Help. In other words, just use the discoverability feature, find the cmdlet you’re looking for, and use the cmdlet. PowerShell will take care of everything for you in the background.
Pretty cool, huh?