PowerShell: Use a Profile for ISE settings

The PowerShell profile is a .Ps1 startup script that runs when you first load the interactive script editor (ise). You can use it to load modules, set a default prompt and default directory, and to map abbreviations to longer command strings.

To see the location of the profile, you simply have to examine the $profile variable:

PS >$profile
 C:UsersLarryDocumentsWindowsPowerShellMicrosoft.PowerShellISE_profile.ps1

The profile can be opened like any other script.

To reload a profile after editing it, you simply need to invoke it using the ampersand “call operator”.

PS> & $profile

If you are reloading an already existing profile…then you may see lots of harmless errors as PS complains about settings that were already in place.

  • Here’s my current profile. It does three things:
  • Changes the prompt to PS>
  • Changes to my default working directory
  • Set an alias of gh for the get-help commandlet
  • Set an alias of np to start notepad++
# Define the powershell Prompt.
function prompt 
{ 
"PS>"
}

# Define the default working directory

Set-Location C:UsersLarryPowershell
PWD  # show the current working directory
# Set an alias for the Get-Help command. 
Set-Alias gh Get-Help
# Set an alias to run the Notepad++ editor 
Set-Alias -Name np -Value "C:Program Files (x86)Notepad++notepad++.exe"

The last command took some experimentation, but I can now type np followed by a file name to open the notepad++ editor with that file.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s