PowerShell Cmdlets

A cmdlet is a PowerShell command with a predefined function, similar to an operator in a programming language.

Key Things to Know About Cmdlets

  • There are system, user and custom cmdlets.
  • Cmdlets output results as an object or as an array of objects.
  • Cmdlets can get data for analysis or transfer data to another cmdlet using pipes (I’ll discuss pipes more in a moment).
  • Cmdlets are case-insensitive. For example, it doesn’t matter whether you type Get-ADUser, get-aduser or gEt-AdUsEr.
  • If you want to use several cmdlets in one string, you must separate them with a semicolon (;).

Cmdlet Naming Convention

A cmdlet always consists of a verb (or a word that functions as a verb) and a noun, separated with a hyphen (the “verb-noun” rule). For example, some of the verbs include:

  • Get — To get something
  • Set — To define something
  • Start — To run something
  • Stop — To stop something that is running
  • Out — To output something
  • New — To create something (“new” is not a verb, of course, but it functions as one)

Common Cmdlets to Practice

Get-Process

Shows the processes currently running on your computer:

Get-Service

Shows the list of services with their status

Get-Content

Shows the content of the file you specify (for example, Get-Content C:\Windows\System32\drivers\etc\hosts)

Finding Cmdlets

Good news — you don’t need to memorize all cmdlets. You can list all cmdlets by executing the Get-Help -Category cmdlet, which will return the following:

You can also create your own custom cmdlets.

Cmdlet Parameters

Each cmdlet has several parameters that customize what it does. The PowerShell ISE will automatically suggest all valid parameters and their types after you type a cmdlet and a hyphen (-):

For example, the following cmdlet shows all services whose names start with “W”:

Get-Service -Name W*

Getting Parameter Information

If you forget a cmdlet’s parameters, just use a script like the following, which will display the parameters for the Get-Process cmdlet:

Get-Process | Get-Member
# "|" sign is a pipe, allowing you to pass data from one cmdlet to another

Getting Examples

If you still don’t find the cmdlet you need, you can make sure the help is current and then get examples for a cmdlet (such as Get-Process) using a script like this:

Update-Help #to update the help data
Get-Help Get-Process -Examples

Cmdlet Aliases

You can also use aliases, which are shortened cmdlet names. For instance, instead of Get-Help you can use just Help. Try running the following two commands and see whether you get the same result:

Start-Process notepad
start notepad

Similarly, to stop this process, you can use either of the following commands:

Stop-Process -Name notepad
spps -Name notepad

To see all aliases, execute the Get-Alias cmdlet.