PowerShell Cheatsheet

Operation cmd PowerShell
Get a simple directory listing
alias: dir
Get a recursive directory listing
dir /s
get-childitem -recurse
alias: dir -r
Get a wide directory list
dir /w
dir | format-wide 
alias: dir | fw
List built-in commands
alias: help
Copy a file
copy foo.txt bar.txt
copy-item foo.txt bar.txt
alias: copy foo.txt bar.txt
Move a file
move foo.txt c:\
move-item foo.txt d:\
alias: move foo.txt d:\
Rename a file
ren foo.txt bar.txt
rename-item foo.txt bar.txt
alias: ren foo.txt bar.txt
Batch rename
ren *.one *.two
dir *.pdf | rename
  -newname {$_.name -rep ".one",".two"}
Set the current directory to d:\
cd \
set-location d:\
alias: cd d:\
Clear the screen
alias: cls
List only directories
dir /ad
dir | where { $_.MshIsContainer }
Directory list, sorted by date
dir /od
dir | sort-object LastWriteTime
Directory list, sorted by date, descending order
dir /o-d
dir | sort-object LastWriteTime -desc
Show the current directory
alias: pwd
See a command’s help
dir /?
get-help get-command 
or: get-help get-command -detailed
or: get-help get-command -full
or: dir -?
List environment variables
dir env:
Delete a file
del foo.txt
remove-item foo.txt
alias: del foo.txt
Find all *.txt files
dir /s *.txt
get-childitem -recurse -include *.txt
alias: dir -r -i *.txt
Find all *.txt files containing a particular string
findstr "foo" *.txt
dir *.txt | select-string "foo"
Show a list of services
net start
Start a service
net start MyService
start-service MyService
Stop a service
net stop MyService
stop-service MyService
Show network shares
net share
gwmi Win32_Share
Show a list of running processes
get-process alias: ps
Kill all notepad.exe processes
taskkill /im notepad.exe /f
ps notepad | kill


One thought on “PowerShell Cheatsheet”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.