Basics
Moving Around
PowerShell utilizes a Verb-Noun
convention for its cmdlets.
# current working directory
Get-Location
pwd
# list current working directory's content
Get-ChildItem
ls
dir
# change directory
Set-Location <path>
cd <path>
# display file's content
Get-Content <file>
type <file>
cat <file>
# clear screen
cls
clear
Clear-Host
History
PowerShell tracks command history in two ways:
Built-in session history (deleted at the start/end of each session)
PSReadLine
module tracks all commands used across all sessions and hosts. By default, it keeps that last 4096 command entered at$($host.Name)_history.txt
located at$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine
.
# session history
Get-History
Id CommandLine
-- -----------
1 Update-Help
2 cd
3 pwd
4 Get-Location
# re-run a command from history
r 4
Get-Location
Path
----
C:\Users\User\Downloads
PSReadLine
will automatically attempt to filter any sensitive information, such as passwords, tokens, API keys, etc.
Get-Content C:\Users\DLarusso\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
Hotkeys
CTRL+R
It makes for a searchable history. We can start typing after, and it will show us results that match previous commands.
CTRL+L
Quick screen clear.
CTRL+ALT+Shift+?
This will print the entire list of keyboard shortcuts PowerShell will recognize.
Escape
When typing into the CLI, if you wish to clear the entire line, instead of holding backspace, you can just hit escape
, which will erase the line.
↑
Scroll up through our previous history.
↓
Scroll down through our previous history.
F7
Brings up a TUI with a scrollable interactive history from our session.
TAB
Autocompletion.
SHIFT+TAB
Move through autocompletion options.
Aliases
# list all aliases
Get-Alias
# create an alias
Set-Alias -Name <alias> -Value <cmdlet>
pwd
, gl
Alias for Get-Location
.
ls
, dir
, gci
Alias for Get-ChildItem
.
cd
, sl
, chdir
Alias for Set-Location
.
cat
, type
, gc
Alias for Get-Content
.
clear
Alias for Clear-Host
.
curl
, wget
Alias for Invoke-WebRequest
.
fl and ft
Alias for formatting output into list and table outputs.
man
Alias for help
.
Last updated