Sunday, July 6, 2008

Setting up a Profile in PowerShell

Profiles in PowerShell are like "rc files" for Linux commands. The profile is a PowerShell script that is run every time you invoke the interpreter. You can use it to set up aliases, create default variables, or anything else that you can do in a PowerShell Script.

Profiles can be per-machine, per-user, or per-shell. See this website for the full details.

To set up your personalized profile for your user account, create the following file:

$env:userprofile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Here's the profile I set up for myself:

# PROFILE START ###########################

# ALIASES
set-alias subst 'subst-output.ps1'
set-alias match 'get-match.ps1'
set-alias ex 'explorer.exe'

# ENVIRONMENT
$env:pathext = (".PS1;" + $env:pathext)

# PATH
cd "$env:userprofile\Documents"

# PROFILE END #############################

No comments: