How to get started with PowerShell

Microsoft's PowerShell offers IT pros a wealth of management capabilities--all from one unassuming console. Learn the basics about how to use PowerShell.

Software engineers working on project and programming in company

Image: nd3000, Getty Images/iStockphoto

Microsoft's PowerShell (PS) console is a powerful framework for managing devices and applications at the software level by blending command-line interface-based (CLI) tools with Microsoft's scripting technologies to format unique language to aid in automating administrative tasks.

For those familiar with the venerable CMD executable, PowerShell functions very similarly on the surface. Enter a command sequence add the appropriate syntax to call specific functions, and run it on the target computer(s) to cause a certain action to occur. That's an oversimplification of the process, but it does well to form the crux of how it works in CMD and PowerShell.

SEE: Manage Active Directory with these 11 PowerShell scripts (TechRepublic Premium)

While this article is aimed more at entry-level PowerShell users and those who have little experience with it, more advanced users may find this information useful, as I explain some of the more difficult to understand concepts of PS, as well as how to go about figuring out why certain things do work, while others don't.

PowerShell is different in that its reach is much faster, as it was designed from the ground up with management and automation in mind. The syntax is also different; it follows a verb-noun format that specifies the action to be taken first, followed by the name of the command. PowerShell allows for changes to be made locally or remotely and to one or many machines, as necessary. Also, special characters are used differently, allowing for cmdlets to be chained to form larger, more complex scripts that work toward a more holistic management approach.

What are cmdlets?

According to Microsoft, "A cmdlet is a lightweight command that is used in the Windows PowerShell environment." Cmdlets are Microsoft's term for commands that are run from within PowerShell. Just like how popular commands like ipconfig, ping, and winver are commands native to CMD.exe, cmdlets are the types of commands native to PowerShell.

Like CMD, cmdlets in PowerShell are upgradable with each version update to the Windows Management Framework. Yet unlike CMD, cmdlets are contained within modules allowing new cmdlets to be introduced, granting PowerShell greater functionality, by importing modules to an existing session. I'll cover more about modules later.

SEE: 10 PowerShell cmdlets you can use instead of CMD commands (TechRepublic)

What are parameters, and how do they work?

Continuing with our example using CMD.exe as a model for comparison, parameters in PowerShell work much like switches in CMD. Parameters are used to include advanced functions to either identify, select, target, or otherwise execute a cmdlet against any number of devices.

Depending on the type of cmdlet being executed, certain parameters will be available that are unique to that specific cmdlet. Additionally, there are common parameters that are intrinsic to PowerShell and are available to all cmdlets that perform specific functions, often used to test, debug, and verify that cmdlets are working (or will work) properly.

What are modules?

Modules exist in PowerShell to provide libraries of functions that perform tasks. The module itself is a file that acts as a collection of cmdlets that reflect the common task they seek to achieve. For example, cmdlets that focus on managing Active Directory (AD) and may be used to read/write data to/from AD reside in the Active Directory module that is installed by default when Remote Server Administration Tools (RSAT) is installed on the client computer.

Modules—delineated by the PSM1 extension—by themselves don't do anything until they are loaded into the PowerShell session. This process of loading the module into PowerShell occurs by running the cmdlet below, which imports the module into the session thereby making the cmdlets associated with it available to the admin during that session only. Once it closes, the module will need to be reimported each time a new session is run.

Import-Module -Name "ActiveDirectory"

Is there a help section I can turn to in PowerShell?

Calling upon our CMD.exe experience, appending the "/?" to command would yield a brief description of the command plus a breakdown of the various switches available and several examples of the command presented on screen.

Microsoft has included an extensive help system for PowerShell in the form of a cmdlet that is typed before the cmdlet you're looking for assistance with, which provides a synopsis explaining what the cmdlet does, the syntax associated with executing the cmdlet, and a full description of the cmdlet, including useful links to aid admins in getting it just right.

Additionally, since Get-Help is a cmdlet in itself, it is subject to a few parameters that add useful functionality for new users and pros alike, as explained below:

  • -examples—Displays examples of the cmdlet being executed.
  • -detailed—Displays extensive information regarding the cmdlet.
  • -full—Displays the entire collection of information regarding a cmdlet.
  • -online—Opens the Microsoft TechNet website containing the latest information regarding a cmdlet.

One last helpful bit about the help cmdlet in PowerShell is that it can be updated on the fly if your device is connected to the internet. By running the sibling cmdlet 'Update-Help' PowerShell will connect to Microsoft's servers to download the latest versions of Get-Help files and update the locally stored files.

Can I get a list of the cmdlets available?

PowerShell includes a cmdlet for this function, too. By running the Get-Command cmdlet, PowerShell will display a running list of all cmdlets available, formatted in alphabetical order and including the Source or module it falls under. This list can be rather exhaustive to sift through in its entirety, so Microsoft has included parameters to help whittle the list down in a more focused manner.

Get-Command -ListImported—Limits the list to only the cmdlets that are available to the current session.

Get-Command -Module "ModuleName"—Limits the list to only the cmdlets that are available to the module named.

Additionally, if looking for information on just one specific cmdlet, it may be included solely without the need for additional parameters, as follows:

Get-Command "CmdletName"

Is it possible to clear the console screen, like in CMD?

Another throwback to CMD.exe which uses "cls" to clear the CLI, PowerShell has a similar method that's easier to remember. Entering the term "clear" and pressing the Enter key will yield the same result—the console screen will be blanked out, removing all previously executed cmdlets, and their subsequent feedback, including errors.

While this is in no way an exhaustive look at PowerShell, my aim is to help those with little to no PowerShell experience gain a better understanding of the powerful features contained in PS. In addition, I provide context on how the framework functions so users can begin to understand the basics, which when coupled with real-world testing, can start them on the path to gaining greater insight while helping them feel more comfortable enough with the console to eventually transition from CMD.

PowerShell tips and tutorials

If you want to learn more about using PowerShell, read these tips on customizing PowerShell settings, uninstalling Edge on Windows 10 using PowerShell, and using PowerShell to manage Microsoft updates on Windows.

Also see