Skip to content

Powershell

hdub-tech edited this page Oct 15, 2026 · 2 revisions

Note

This was whipped together quickly while doing some cramming, so you might see some notes and think "well why didn't you just research further?". Valid question. Answer: aintnobodygottimeforthat.gif. Seriously, I'm super pressed for time rn.

Also, probably doesn't belong in the "Programming Languages" category, I know. I didn't even have time to come up with better organization rn.

Coming from Bash

I'm diving into Powershell but I have all the muscle memory of Linux commands. Here is a map of the ones I commonly use and some resources for those like me.

Couple must know;s about pwsh

  1. You can install it on linux (and MacOS), and play around by simply running pwsh (or pwsh-preview) if you don't have access to a Windows box.
  2. Get-Command *STRING* - trying to find a command and only know part of the name? Use this.
  3. Get-Help COMMAND - get a man page basically. Add -examples to the end to go straight to how to use it.
    • If you see Get-Help cannot find the Help files for this cmdlet on this computer. try running Update-Help (which fixed an issue I saw on pwsh-preview in Ubu26.04.

Resources

I used the following for a lot of this:

  1. Unix Person's Guide to Powershell

Bash -> pwsh

Bash Powershell Notes
alias ALIAS_NAME COMMAND Set-Alias ALIAS_NAME COMMAND There are some quirks with this, see the help
basename FILE - dir FILE | select name
- [System.IO.Path]::GetFileName('FILE')
For the first, FILE must exist. For the latter, it does not.
cd Set-Location Fortunately, this is aliased to cd
cp [-r] Copy-Item [-Recurse] Also aliased.
date - Get-Date
- Set-Date
dirname FILE - Get-ChildItem FILE | select directory
- [System.IO.Path]::GetDirectoryName('FILE')
For the first, FILE must exist. For the latter, it does not.
echo - Write-Object
- Write-Host
env/set - Get-ChildItem Env:
-get-variable
The first is for Windows-level vars, the second for PowerShell-level variables
find . -name '*.md' dir *.md -recurse | Select FullName I've been playing with this and getting weird results if I try to use -Include/-Exclude
for n in One Two Three
do
echo $n
done
foreach ($n in ("one", "two", "three")) {write-output $n}
grep Select-String This acts "weird" when piped to from a command, like get-alias | select-string ls will return only ls rather than the whole line (so like grep -o but using it with file output
head Get-Content file.txt | select-object -first 10
history Get-History History doesn't persist across sessions unless you do work to make it do so.
hostname - hostname
- Get-WmiObject -class win32_operatingsystem | select __SERVER
Get-WmiObject wasn't on my pwsh-preview in Ubuntu 26.04
[-f FILENAME] Test-Path FILENAME Test-Path returns True/False
kill Stop-Process
ls - Get-ChildItem
- dir
- gci
Should be aliased already
ls -a - Get-ChildItem -force Shows all files including hidden ones
lsusb get-wmiobject Win32_USBControllerDevice gwmi is an alias for Get-WmiObject
man Get-Help Super helpful parameters: -examples and -full. If things are "not found" with Get-Help, try running Update-Help
mv Rename-Item
ps -ef | grep ssh get-process *ssh* Roughly equivalent, but when running the latter in ubuntu powershell, due to lack of full command line, a few were missing (Ex: "vagrant ssh" didn't show).
read -p "Input pls: " innie; echo $innie $innie = read-host "Input pls: " -MaskInput There is also -AsSecureString which creates a System.Security.SecureString which I don't know yet how to read
rm Remove-Item
sleep SECONDS Start-Sleep SECONDS Might have a sleep alias already. Also has a -milliseconds parameter
sort sort-object Also has a -Unique parameter, among others
tail Get-Content -tail 10 file.txt
tail -f Get-Content -tail 10 -wait
tee [-a] FILENAME Tee-Object [-Append] FILENAME
touch FILENAME Set-Content -Path FILENAME -Value $null For an empty file
unalias Remove-Item -Path Alias:ALIAS_NAME
uname -a - get-wmiobject -class win32_operatingsystem | select *
- get-wmiobject -class win32_computersystem | select *
Roughly same output there
uptime get-wmiobject -class win32_operatingsystem | select LastBootUpTime You can also add -ComputerName to check the uptime of another server
wc -l Get-Content FILE | measure-object | select count Non-blanks, drop the select and add -line
whoami [Security.Principal.WindowsIdentity]::GetCurrent() | select name

Clone this wiki locally