Anna's notepad

Create a Powershell cheatsheet

Aliases

In Powershell, you can set an alias (custom command) for a session by typing it directly:

function thanksbeef { echo "You're welcome, beefsack." }
Set-Alias -Name thankyou -Value thanksbeef

This is a simple function: type thankyou and the shell responds with You're welcome, beefsack. This behaviour will stop as soon as you exit or restart Powershell.

Create a file with permanent aliases

You can create a text file and keep all your Powershell aliases in there, and they'll be available in every Powershell session.

Find your profile location with the command:

echo $profile

The result will be something like:

my_username\My Documents\PowerShell\Microsoft.PowerShell_profile.ps1

Create a new text file and save it at that path with that filename.

Put your aliases in this file, and restart Powershell.

A useful thing to do is bung a list of your most frequently-used commands into an alias called something like 'cheatsheet'. You can then type 'cheatsheet' into Powershell whenever you want a reminder!

function mycheats {
Write-Host "Some text"
Write-Host "Some more text"
Write-Host "A third line of text"
}
Set-Alias -Name cheatsheet -Value mycheats

Notes:

#MS Powershell