How do I teach myself to use new PowerShell extensions?

As the Microsoft-centric world continues to become more PowerShell-enabled, you'll quickly find your computers littered with PowerShell extensions, which is a good thing. But how can you teach yourself to use them?

Step 1: Installation

A decent amount of extensions will always be installed by default with your operating system, but other ones - such as those related to server products - will need to be installed. For example, the Windows 7 Remote Server Administration Toolkit includes the extensions that ship with Windows Server 2008 R2, so that you can have those extensions on your management workstation. For server products (Exchange, SQL Server, etc), you'll generally just install the product's normal "Admin Tools" option on your client. This step will give you any graphical consoles normally used to manage the product, as well as any PowerShell extensions.

Step 2: Discovery

Next, you need to find the extensions. PowerShell supports two kinds of extension: Modules and PSSnapins. Snap-ins must always be installed and registered with the system, so you can find them by running this command in PowerShell:

Get-PSSnapin -registered
For modules, things can be a bit trickier. The PSModulePath environment variable tells PowerShell where modules should be located; in practice, only OS-related modules tend to be installed in that path. For those, you can discover them by running this:

Get-Module -ListAvailable
However, you should also run a file search for files with a .psd1 or .psm1 filename extension, as those are also modules and may exist outside the predefined PSModulePath location.

Step 3: Loading

Once you've found an extension, you need to load it into the shell. This works a lot like loading a snapin into the MMC: You'll have to do it every time you open a new shell window (you could also put the loading command into a profile script to have it happen automatically when you open new shell windows). For PSSnapins:

Add-PSSnapin <snapinname></snapinname>
For modules, you can use just the module name for any module located in the PSModulePath locations; for modules located elsewhere, provide the complete path to the module. 

Import-Module <module_name module_path></module_name>

Step 4: Discovering

Now, what did that extension just add in terms of commands?

Get-Command -module <module_name>
Get-Command -pssnapin <module_name></module_name></module_name>

That shows you how to find the newly-loaded commands in a module or PSSnapin, respectively. Keep in mind that modules and PSSnapins may also add new PSProviders, meaning they give you a new type of storage to map into PowerShell as a drive. Some extensions may even automatically map a new drive. To see, run these commands:

Get-PSProvider
Get-PSDrive

From there, you can start asking for help on the new cmdlets to see how to use them.

Please or Register to post comments.

What's PowerShell with a Purpose Blog?

Don Jones demystifies Windows PowerShell.

Blog Archive

Sponsored Introduction Continue on to (or wait seconds) ×