Product and service reviews are conducted independently by our editorial team, but we sometimes make money when you click on links. Learn more.
 

PowerShell Basics: Intro To Tools, Commands and Modules

PowerShell Basics: Intro To Tools, Commands and Modules
By

PowerShell is a powerful automation and configuration management framework that enables systems administrators to be more productive by automating repetitive, tedious tasks. If you're new to PowerShell, start with the basics of tools, cmdlets and modules.

You've probably been hearing good things about PowerShell for a while now. Chances are you or your boss have said it's something you need to learn and put to use. But at this point PowerShell has exploded into a significant aspect of Microsoft's hybrid cloud strategy, so where do you start? As with most things in life, taking the time to learn and fully understand the basics will go a long way toward avoiding headaches and will help you grasp more advanced concepts as you delve deeper into the world of PowerShell commands. The three concepts introduced in this article are fundamental to understanding the key concepts that form the basis of PowerShell.

MORE: Intro To PowerShell DSC
MORE: PowerShell Tutorials 

PowerShell Tools

PowerShell is installed by default in Windows 7, Windows Server 2008 R2, and later versions of Windows. Newer versions of PowerShell introduce new features and cmdlets, Microsoft's term for PowerShell commands, and are installed using the corresponding version of the Windows Management Framework (WMF). Currently WM4 is the latest version recommended for production use, with WM5 available as a preview. In some cases several new features or cmdlets are dependent on the operating system in addition to the WMF version. For instance, Windows 8 and Windows Server 2012 support the Test-NetConnection cmdlet, which allows you to test connectivity to a specific TCP/IP port, but this cmdlet is not available in Windows 7 even when running the latest WMF version.

On most Windows systems users will have the availability of two PowerShell environments, the PowerShell console and the PowerShell ISE. The PowerShell console appears like the traditional command line, but with the full weight of PowerShell behind it. Variable names, loops, tab completion, and piping are all available from the PowerShell console. For more in-depth use (such as script building) the PowerShell ISE (Integrated Scripting Environment) offers tab completion, code highlighting, and Microsoft’s Intellisense code completion capability to assist you in creating and testing your PowerShell code. The PowerShell ISE also allows you to work with multiple PowerShell scripts simultaneously using tabbed navigation.

MORE: PowerShell Objects, Piping, Filtering And More

PowerShell Cmdlets

The basis of PowerShell commands are cmdlets. The folks at Microsoft made several design strategies when designing PowerShell cmdlets. First is the ability to easily infer cmdlet names, or at the very least make them easy to discover. PowerShell commands, or cmdlets, are also designed to be easy to use with standardized syntax, making them easy to use interactively from the command line or to create powerful scripts.

PowerShell cmdlets use the Verb-Noun format as in Get-Service, Stop-Service, or Import-Csv. The verb portion of the cmdlet name indicates the action to be performed on the noun. Typically cmdlets used to request information use the Get verb, as is the case with Get-Process or Get-Content. Commands used to modify something will usually begin with the verb Set, while those adding a new entity to something often begin with Add or New. In many cases these verb-noun combinations can be guessed or predicted because of the standard naming convention.

Standardized cmdlet naming isn't the only aspect of PowerShell designed to improve command line usability. Parameters commonly used throughout PowerShell also use standard names. One example of this is the -ComputerName parameter, which allows a cmdlet to be executed against one or more remote computers. Likewise, -Credential is used to provide a credential object, containing a user's login credentials, in order to run the command as a specific user.

When using PowerShell via the console, aliases can be used for both cmdlets and parameters in order to conserve keystrokes and shorten the overall length of a command (an advantage which should not be overlooked when piping commands together). Cmdlet aliases do not always use a standard naming convention, however they do often mirror traditional command line utilities.

In PowerShell the aliases dir, cd, del, and cls correspond to the Get-ChildItem, Set-Location, Remove-Item, and Clear-Host cmdlets respectively. Parameter aliases can work in two ways: they can utilize a predefined alias defined by the cmdlet, or they can be aliased by entering enough characters to result in a unique match among the cmdlet’s supported parameters.

MORE: PowerShell Help, Cmdlet Discovery And Object Exploration

PowerShell Modules

Introduced in PowerShell version 2, modules are packages containing one or more cmdlets which extend the capabilities of PowerShell. Many modules are installed along with the Remote Server Administration Tools (RSAT) used to manage Windows servers. Other modules can be downloaded from third party developers in order to automate management of their products, or those simply providing a means to ease the task of managing your enterprise infrastructure. It goes without saying that third party PowerShell modules (or scripts of any kind) should be acquired from trusted sources, and tested thoroughly prior to production use.

Modules can be enabled using the Import-Module command, making them available to the current PowerShell session. Advanced PowerShell users can even create their own PowerShell modules, providing corporate administrators a means to create tools customized specifically for their administrative requirements.

MORE: Managing Files And Folders With PowerShell
MORE: Managing Active Directory With PowerShell