Powershell

What is a PowerShell cmdlet (command-let)?

A basic unit of a command inside Windows PowerShell is referred to as cmdlet(pronounced as command-let). All cmdlets have a verb-noun format and there are hundreds of cmdlets that can be used in Windows PowerShell. All these cmdlets can be used in both upper as well as lower case because Windows PowerShell is not Case-sensitive.This write-up briefly describes the cmdlet in PowerShell with the below-listed learning outcomes:

So, let’s begin!

What is a PowerShell cmdlet

It is a very simple and a lightweight command that is used in Windows PowerShell environment and is commonly pronounced as command let. Cmdlets are a special type of .Net classes that implements some specific tasks/operations and Windows PowerShell can invoke/call them at runtime through the APIs.

Cmdlet names

In PowerShell, the names of the cmdlets are designed based on a special pattern i.e. verb-noun pair. The Verb in the cmdlet determines the action that the cmdlet performs while the Noun determines the resource on which the specified cmdlet will perform the action.

Cmdlet Parameters

The PowerShell cmdlets can have some mandatory and optional parameters that control how the cmdlet operates. Different parameter types of the cmdlet are listed-below:

  • Named Parameters: Use Parameter’s entire name while calling the script/function.
  • Positional Parameters: there is no need to specify the parameters name, only type/specify the arguments in a relative order.
  • Switch Parameters: These parameters can be used in place of the Boolean parameters.
  • Dynamic Parameters: The parameters that are passed to a cmdlet at runtime.
  • Parameter Set: Multiple parameters can be used within the same command to perform a specific task.

Difference between cmdlets and commands

The cmdlets differ from the commands in the below-listed aspects:

  • Cmdlets are the objects of .NET classes and they are not just stand-alone executables.
  • The command-lets can be made from a few dozen lines of code.
  • The cmdlets don’t handle their parsing, output formatting, or error presentation instead it is performed by the Windows PowerShell at runtime.
  • Cmdlets utilize the pipeline to process the input objects, similarly, cmdlets deliver objects as output to the pipeline.
  • Cmdlets process only a single object at a time hence the cmdlets are record-oriented.

Frequently Used cmdlets

PowerShell includes hundreds of cmdlets and among them the most frequently used cmdlets are listed in the below-given table:

cmdlet Description
Get-Command It provides/retrieves all the cmdlets installed on a computer.
Get-ChildItem It is used to get the items as well as the child items in one or more locations.
Get-Help Provides a detailed information about the specified cmdlet
Get-Location Provides the current directory location.
Set-Location Sets the current directory location.
Stop-Process It is used to stop/terminate a process.
New-Item It creates a new empty file/directory.
Copy-Item Copies the files/items from one location to the other within the same namespace.
Remove-Item It is used to remove a file/directory.
Move-Item It is used to move a file from one location to the other.
Rename-Item This cmdlet is used to rename a file.
Invoke-GPUpdate Refreshes the group policy update.
Add-Computer Joins the computer to a domain.
Restart-Computer This cmdlet restarts the operating system on a local/remote computer.
Stop-Computer This cmdlet is used to shut down the local or remote computers.

How to use cmdlet in PowerShell

Let’s consider a couple of examples to understand how cmdlets work in PowerShell:

How Get-Help Cmdlet works in PowerShell

The code block given below will assist you to understand the working of Get-Help cmdlet:

Get-Help New-Item

In the above snippet, We utilized the Get-Help cmdlet to get the detailed information about the New-Item cmdlet.

How Get-Location Cmdlet works in PowerShell

In this example, we utilized the Get-location cmdlet to get the location of the current directory:

Get-location

The output shows that the Get-location cmdlet returns the current directory location.

Conclusion

A basic unit of a command inside Windows PowerShell is referred to as cmdlet(pronounced as command-let). The PowerShell cmdlets can be invoked programmatically using the Windows PowerShell APIs. In PowerShell, there is a wide range of cmdlets that are used to perform different tasks for example the Get-Help cmdlet provides a detailed information about the specified cmdlet, Get-Location cmdlet provides the current directory location, the Set-Location cmdlet sets the current directory location, and so on. This write-up presented a comprehensive overview of PowerShell cmdlets.

About the author

Anees Asghar

I am a self-motivated IT professional having more than one year of industry experience in technical writing. I am passionate about writing on the topics related to web development.