PowerShell Cmdlet

Windows PowerShell provides a set of commands and these are called “cmdlets” or “Command lets“. These are lightweight and run by PowerShell runtime from the command line or from windows PowerShell API. Cmdlets are based on .NET classes and use .NET objects. Thus, cmdlets can receive objects as input and deliver objects as output, which can then feed the input of subsequent objects, enabling cmdlets to form a command pipeline.

Most cmdlets support the use of parameters as part of the input. Parameters can be added to the cmdlet at the command line or passed to cmdlets through the pipeline as the output from a previous cmdlet.

These cmdlets are used in automation script collectively to perform any action on the server. The CMD commands and cmdlets are two different things.

For example, if we need to change the current directory from one to another so in that case, we use the “cd” command and the “Set-Location” cmdlet is the replacement of the cd command in PowerShell.

Syntax:  Set-Location “<Path>”

Example:  Set-Location “C:\test\New folder”

Powershell-cmdlet

For this particular example, “cd” or change directory, the command is super popular but PowerShell cmdlet is extremely powerful to perform the different day-to-day administrative operations.

How to get all PowerShell cmdlets

To check all available PowerShell cmdlets execute the below Get-Command cmdlet from the PowerShell command line.

Get-Command -commandtype cmdlet

How to get help for PowerShell cmdlet

To explore help for PowerShell cmdlet execute the below Get-help cmdlet from PowerShell command line.

Get-Help <Cmdlet-name>

There are two types of help for the cmdlet local and online. If we did not add the “-online” parameter to “Get-Help” cmdlet it searches for local help else if we added the “-online” parameter to any cmdlet it searches the Microsoft online Library for the desired cmdlet.

Get-Help <Cmdlet-name> -online

Powershell provides hundreds of cmdlets which can be used to perform daily day to day system administrator tasks below is the list of some popular cmdlet.

SNo. PowerShell Cmdlet Description
1. Write-Host Write something on the console.
2. Get-Location Get the current directory physical location.
3. Get-Content Read the content of the specified file.
4. Get-ChildItem List items in a directory.

 

5. Get-Help Get more information about a specific cmdlet that can be local or online.
6. Stop-Process Terminate a running PowerShell process.
7. Set-Location Change the current directory path.
8. Copy-Item Copy files.
9. Remove-Item Remove a file or directory.
10. Move-Item Move a file from one location to another.
11. Rename-Item Rename a file.
12. New-Item Create a new empty file or directory.
13. Stop-Computer Shut down a local or remote computer.
14. Restart-Computer Restart a local or remote computer.
15. Add-Computer Join a computer to a domain.

 

Apart from the above, there are many important cmdlets kindly check the complete list by above “Get-Command” cmdlet.

Difference between Command Line(CMD) & PowerShell Cmdlet

SNo. Command Line(cmd) PowerShell Cmdlet
1. Only Interpret Batch command. Execute both Batches as well as PowerShell commands.
2. Not Support Intellisense. Support Intellisense.
3. Default window operation system commands. Cmdlets are instances of .NET classes
4. Only return the output in text. It returns the output in the text as well as the collection of objects.
5. It Handled by PowerShell Runtime of executing, parsing, and debugging of the script. It handled by windows OS.
6. Execute as standalone commands. Execute as standalone as well as in long automation scripts.

This is the basic overview of cmdlets as a developer or a system administrator you do not need to learn each cmdlet only just need to focus on day-to-day tasks, which can be automated using these cmdlets.