Powershell
Basic notes for powershell and its explanations
Aliases are the shorthand notes for the commandlets, it lets to identify the correct commandlet of the specified alias
Get-Alias iwrProvides help of the specified commandlet, if -Examples is specified the usage examples are also provided
Get-Help Get-ChildItem
Get-Help Get-ChildItem -ExamplesLists the available commandlets with the sepecified noun and verb
Get-Command "Get-*"
Get-Command "*-Service"Know the propeties of a command
Get-NetTCPConnection | Get-MemberReference
$_ --> refers to the element which is pipedReferncing with conditions
# ? --> alias to where
# $_ --> refers to the ouptut of the Get-NetTCPConenction
# LocalAddress --> an members of the Get-NetTCPConnection cmdlet
Get-NetTCPConnection | ? {$_.LocalAddress -eq "127.0.0.1"}
Get-NetTCPConnection | Where-Object {$_.LocalAddress -eq "127.0.0.1"}Only select contents whose contents are not empty
# $null --> value of the emptry string in powershell
Get-Process | ? {$_.Path -ne $null } | Select-Object pathHead / tail in powershell
# head
Get-Process | Get-Member | Select-Object -First 10
# tail
Get-Process | Get-Member | Select-Object -last 10The
gettype()is used to identify the output type from a commandBased on the type of output, we can query it accordingly
(whoami).gettype()
(ls).gettype()Once the type is identified, the parameters that support the ouptut of the commandlet can be identified with
Get-Member
whoami | Get-MemberThe methods and properties of the specified commandlet can be accessed with
().operator
# accessing property
(whoami).length
# accessing mehtod
(whoami).ToUpper()The commands can be nested or can be used as a subset with the ()
The
Format-Table, Format-List, Format-Customare common ways to show an output
(New-Object -com "Microsoft.Update.AutoUpdate").Results | Format-ListThe
2>/dev/nullequivalent of powershell is-ErrorAction
Get-ChildItem -ErrorAction 'SilentlyContinue'ls -laof powershellGet-ChildItem -Force
Last updated
Was this helpful?