command.com
, cmd.exe
, and cscript
and has been build-in since Windows 7 and Server 2002 R2verb-noun
and it supports Object Orientationverb-noun
patternGet-Command set* #show cmdlets starting with set
Get-Command #show all the cmdlets that powershell knows about
Get-Command -verb "keyword" #show all the verbs with the corresponding keyword
Get-Command -noun "keyword" #show all the corresponding nouns
cmdlet -whatif #show what will happen after this cmdlet is executed
Set-
, Get-
, New-
, Read-
, Find-
, Start-
Many cmdlets have aliases making them much easier to use
#We can use the alias command to show all the aliases that are there
alias
CommandType Name
----------- ----
Alias ? -> Where-Object
Alias % -> ForEach-Object
Alias cd -> Set-Location
[redacted for brevity]
#To get alias for a specific cmdlet
Get-Alias -definition <cmdlet>f
Get-Help
cmdlet or its alias help
help [cmdlet/ alias]
help [cmdlet] -detailed
help [cmdlet] -examples
help [cmdlet] -full
help [cmdlet] -online
|
b/w cmdlets, we are not piping streams of actual data, we're piping the objects (which makes it so powerful) viz. we don't have to parse and can just pull out stuff from the passed-on object we want.#Show a list of methods and properties of each object
cmdlet | Get-Member
cmdlet | Format-List
cmdlet | Format-List -property [property]
cmdlet | Format-List -property *
<aside>
👉 ForEach-Object % {$_})
</aside>
ForEach-Object
is aliased with %
$_
Get-Process -name nc | % {stop-process $_}
Get-Process -name nc | ForEach-Object {stop-process $_}
100, 200, 500 | % {$_ * 50}
100, 200, 500 | ForEach-Object {$_ * 50}
<aside>
👉 Where-Object ? {$_})
</aside>
Get-Command | Get-Member
Get-Command | Where-Object {$_.status -eq "running"}
Get-Command | ? {$_.status -eq "running"}
$
and for environment variables prepend $env:
ls env:
ls variable: