How-To

Bash to PowerShell Cheat Sheet

While Tom was learning PowerShell, he found himself trying to translate the bash commands he was familiar with into the PowerShell commands that accomplish the same task, coming up with this handy cheat sheet.

Recently I have been doing some PowerShell programming, which still presented a learning curve despite my rich background in bash programming. PowerShell and bash have programming languages that are, although both very good at what they do, based on totally disparate philosophies. An example that perhaps best underlines this difference is that PowerShell cmdlets return objects, while bash commands return text.

While I was learning PowerShell, I found myself trying to translate the bash commands I was familiar with into the PowerShell commands that accomplish the same task. I started to track these commands, and below is a list that I came up with.

Bash

PowerShell

PowerShell Alias

Example

Note

Cd

Set-Location

Cd, sl, chdir

Set-Location -Path .\Desktop\

Change Directory

Cp

Copy-Item

Cp, copy cpi

Copy-Item -Path .\DemoFile.xlsx -Destination .\NewFile.xlsx

Copy a file

Find

Get-ChildItem

Get-ChildItem -Filter "*RDP*" -Recurse -File

Find a file

Kill

Stop-Process

Get-Process -Name Zoom

Ls

Get-ChildItem

Ls, dir

Get-ChildItem $env:USERPROFILE\desktop | Sort-Object -Property LastWriteTime

Man

Get-Help

Get-Help Test-Connection -Full

Manual for a command

Man -k

Get-Command

Get-Command -Name "*dns*"

Find a command

Mkdir

New-Item

New-Item -ItemType Directory -Name ‘Articles’

Make directory

Ping

Test-Connection

Test-Connection 10.0.0.6 | Format-Table -AutoSize

Ps

Get-Process

Get-Process zoom | FL

pwd

Get-Location

Pwd, gl

Get-Location

Get present working directory

Rm

Remove-Item

Rm, ri, rmdir, rd, del

Remove-Item -Recuse -Force

Remove directory

Tail

Get-Content

Get-Content -Tail 7 '.\CU Insights - Computer Trends.csv'

Display the last 7 lines of a text file

Touch

New-Item

New-Item -ItemType File -Name “Article”

Create a new, empty file

Wc

Measure-Object

Get-Content '.\CU Insights - Computer Trends (5).csv' | Measure-Object -Character -Line -Word

Wc = Word count

Whoami

whoami

whoamu

Display the username

Below are few screen captures of these PowerShell commands being run.

[Click on image for larger view.]
[Click on image for larger view.]
[Click on image for larger view.]

Although PowerShell is a different beast than bash, and it has taken time for me to wrap my head around it, I do see the power of having object rather than text-based output. It does offer some advantages in flexibility, albeit at the expense of complexity. Hopefully you will find the above commands helpful if you need to transition from bash to PowerShell. As an alternative, you can always use Windows Subsystem for Linux (WSL) to use bash and other Linux/Unix tools you are familiar with on your Windows 10 system.

About the Author

Tom Fenton has a wealth of hands-on IT experience gained over the past 30 years in a variety of technologies, with the past 20 years focusing on virtualization and storage. He previously worked as a Technical Marketing Manager for ControlUp. He also previously worked at VMware in Staff and Senior level positions. He has also worked as a Senior Validation Engineer with The Taneja Group, where he headed the Validation Service Lab and was instrumental in starting up its vSphere Virtual Volumes practice. He's on X @vDoppler.

Featured

Subscribe on YouTube