PowerShell v3 and Windows Server 2012 – Discoverability

Home > Blogs > PowerShell > PowerShell v3 and Windows Server 2012 – Discoverability

PowerShell v3 and Windows Server 2012 – Discoverability

Like This Blog 0Jason Helmick
Added by June 22, 2012

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.

PowerShell 2.0
PowerShell 2.0 was released with a lot of discoverability features. Discoverability meaning, it will help you find what you’re looking for.

Get-Help:

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.

PowerShell get help services cmdlets that 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

Windows PowerShell 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*

Windows PowerShell Get-Help web

This doesn’t return a list of web administration cmdlets, although it does return a cmdlet, its not the right one

NAME
New-WebserviceProxy

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.

You may also like:  CompTIA Series: Risk Analysis Calculations

PS C:\ Import-Module WebAdministration
PS C:\ Get-Help *web*

PS C:\>  get-module
PS C:\>

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

 Windows PowerShell 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*
PS C:\>

The module’s in now imported and now we can use Get-Help * web * for this module.

PS C:\> get-help *web*

PowerShell now provides all the available cmdlets for *web*.
Windows PowerShell 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.

PowerShell Get-Website

 

Windows PowerShell Get-Website

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.

PowerShell V3 Microsoft Windows Server 2012
We'll start with Get-Help on Service.

PS C:\ get-help *service*

PowerShell v3 returns a list of cmdlets for services, just as you would expect.

You may also like:  Virtual machine configuration Versions in Windows Server 2016

PowerShell v3 Windows Server 2012 get-help

Windows Server 2012 comes with more PowerShell modules than previous versions.

modules PowerShell v3 Windows Server 2012

 

PS C:\> Get-Module -ListAvailable

PowerShell v3 Get-Module ListAvailable Windows Server 2012

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.

PowerShell v3 Get-Help cmndets ListAvailable Windows Server 2012

Additionally, V3 returns not only the list of cmdlets available, but also the module it’s coming from.

PowerShell v3 Get-Help cmndets ListAvailable Windows Server 2012

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.

PowerShell v3 Get-Website Windows Server 2012

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.

PowerShell v3 Get-Website Windows Server 2012
The module is dynamically loaded so the cmdlet can execute.

PowerShell v3 Get-module Windows Server 2012

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?

Knowledge is PowerShell.
Jason Helmick
Jason Helmick
Director of PowerShell Technologies
Interface Technical Training

Videos You May Like

Agile Methodology in Project Management

0 41 0

In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management

Creating Users and Managing Passwords in Microsoft Office 365

0 53 1

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.

Detailed Forensic Investigation of Malware Infections – April 21, 2015

2 122 1

In this IT Security training video, Security expert Mike Danseglio (CISSP / CEH) will perform several malware investigations including rootkits, botnets, viruses, and browser toolbars.

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.