A blog by Jose Barreto, a member of the File Server team at Microsoft.
All messages posted to this blog are provided "AS IS" with no warranties, and confer no rights.
Information on unreleased products are subject to change without notice.
Dates related to unreleased products are estimates and are subject to change without notice.
The content of this site are personal opinions and might not represent the Microsoft Corporation view.
The information contained in this blog represents my view on the issues discussed as of the date of publication.
You should not consider older, out-of-date posts to reflect my current thoughts and opinions.
© Copyright 2004-2012 by Jose Barreto. All rights reserved.
Follow @josebarreto on Twitter for updates on new blog posts.
As I continue to experiment with PowerShell v2 in Windows Server 2008 R2, I will share some of what I learn here on the blog. This time I am focusing on Cmdlets, Snap-ins and Modules.
Cmdlets
Windows PowerShell introduced the notion of a “cmdlet” (you pronounce it “commandlet”). These are like tools or commands that are typically very simple and to the point (although most have properties or parameters). For instance, there is one to restart a computer (Restart-Computer), one to list the hotfixes installed on a computer (Get-Hotfix) and one to invoke a WMI method (Invoke-WmiMethod). You can get a list of cmdlets using a cmdlet called Get-Command. You can also learn more about a cmdlet by using a cmd-let called Get-Help.
Try these:
Verbs and Nouns
You probably noticed that the name of the cmdlets are always divided into two parts, separated by a dash. The first part describes the type of action (called the “Verb”) and the second part describes the object where the action is performed (called the “Noun”). You will notice that the way verbs and nouns are used are quite consistent. You will see some verbs being frequently used, like “Get”, “Set”, “New” and “Remove”. Common nouns include “Item”, “Object”, “Service”, “EventLog”, “Computer” or “Job”. Not every combination of verb and noun is implemented though, you can use Get-Command and Get-Help to find more.
Parameters
Cmdlets also commonly include parameters. As with the regular command prompt in Windows and with most command-line tools, these will inform the cmdlet details about what to do. They are many times optional. There is usually a default parameter that can be provided right after the cmdlet name. Others must be explicitly declared by the parameter name starting with a dash. The Get-Help cmdlet, for instance, can be provided with a default parameter to indicate what cmdlet you need help on. You can also specify optional parameters like -examples or -detailed. Parameters vary widely between cmdlets. You can use Get-Help to learn more about the parameters for a specific cmdlet.
Snap-ins
PowerShell can be extended in a number of ways and one of them is to add more cmdlets. The built-in cmdlets, for example, come from some PowerShell Snap-ins. A number of those snap-ins are loaded by default. By default, in Windows Server 2008 R2, the following snap-ins are loaded. You can get a list with Get-PSSnapin:
The Get-Command and Get-Help cmdlets, for instance, come from Microsoft.PowerShell.Core Snap-in. You can load addition snap-in (with Add-PSSnapin). Snap-ins are basically .NET program compiled into DLL files and they can also include (in addition to cmdlets), providers and functions. The snap-in definition includes
Modules
With PowerShell v2, cmdlets can also be defined in another type of extension called Modules. By default, Windows Server 2008 R2 PowerShell will not import any modules, but there are a number of modules available for importing. These modules are described in files you can find under the c:\Windows\System32\WindowsPowerShell\v1.0\Modules\ folder, including files with a "psd1" extension that contain details about the module in plain text. Here is a list of the modules available in Windows Server 2008 R2:
The ServerManager module, for instance, provides cmdlets that can be use to manage Roles, Role Services and Features in Windows (they replace the deprecated ServerManagerCmd.exe tool).
I hope this helped you understand a bit more about cmdlets in PowerShell. Try the sample commands (for Windows Server 2008 R2) and keep on learning...