Cmdlet In PowerShell
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed the execution policy in PowerShell.
https://cloudaffaire.com/execution-policy-in-powershell/
In this blog post, we will discuss cmdlet in PowerShell and how to get started with PowerShell cmdlet. Cmdlet is a set of built-in PowerShell commands that can be used to interact with other cmdlets or used as a tool for automation. The basic difference between a cmdlet and a normal command is that cmdlet returns objects instead of plain text when executed. PowerShell comes with a set of pre-installed cmdlet provided by PowerShell. You can add additional PowerShell provided cmdlet or create your own custom cmdlet.
You can list all available cmdlet using Get-Command cmdlet. Each cmdlet has a predefined set of parameters that can be used with the cmdlet to control its behavior. You can get the list of parameters using Get-Help cmdlet. There are also some common parameters that can be passed to every cmdlet. Each cmdlet returns some objects as output. You can get a list of all objects using Get-Member cmdlet.
Cmdlet In PowerShell:
List All Cmdlet Available In PowerShell:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
######################### ## PowerShell | cmdlet ## ######################### ## PowerShell Latest Version (5) ## get all commands that are installed on the computer, ## including cmdlets, aliases, functions, filters, scripts, and applications Get-Command ## get all cmdlet Get-Command | Where-Object {$_.CommandType -eq "Cmdlet"} |
Get Help For Specific Cmdlet In PowerShell:
1 2 3 4 5 |
## get help on a cmdlet Get-Help Get-Process -Full Get-Help Get-Process -Online |
Execute A Cmdlet In PowerShell:
1 2 3 4 5 |
## execute a cmdlet Get-Process Get-Location |
Get All Properties And Methods Of A Cmdlet In PowerShell:
1 2 3 4 5 6 7 |
## get members of cmdlet Get-Process | Get-Member Get-Process | Get-Member -MemberType Properties Get-Process | Get-Member -MemberType Method |
Filter Output Objects In PowerShell:
1 2 3 |
## where objects Get-Process | Where-Object { $_.Id -le 500 } |
Select Output Objects In PowerShell:
1 2 3 |
## select objects Get-Process | Where-Object { $_.Id -le 500 } | Select-Object ProcessName,Id,Threads |
Sort Output Objects In PowerShell:
1 2 3 4 5 |
## sort objects Get-Process | Where-Object { $_.Id -le 500 } | Sort-Object -Property Id Get-Process | Where-Object { $_.Id -le 500 } | Sort-Object -Property Id -Descending |
Group Output Objects In PowerShell:
1 2 3 4 5 |
## group objects Get-Process | Select-Object Name,PM | Group-Object -Property Name Get-Process | Select-Object Name,PM | Group-Object -Property Name | Sort-Object -Property Count -Descending |
Process Each Output Objects In PowerShell:
1 2 3 |
## foreach objects Get-Process | ForEach-Object -Process {Write-Host $_.ProcessName (($_.PM)/1MB) "MB"} |
Format Output Objects In PowerShell:
1 2 3 4 5 |
## format objects Get-Process | Format-Table -RepeatHeader Get-Process | Format-Table ProcessName, @{Label="TotalRunningTime"; Expression={(Get-Date) - $_.StartTime}} |
Hope you have enjoyed this article; we will cover most of the important cmdlet one by one in coming blog posts. In the next blog post, we will discuss Get-Help cmdlet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation