MSH: Reloading Your Profile

As you experiment with your profile ($Home\My Documents\MSH\Micrsoft.Management.Automation.msh_profile.msh) you quickly get tired of having to fire up a new shell to try your changes.  You can reload your profile easily like so:

> . $profile

$profile is a MSH variable that contains the full path to your profile file.  One thing to keep in mind about reloading your profile is that you might run into certain problems.  First, MSH doesn’t like it when you remove an alias that has already been removed.  You can usually work around this type of problem by ignoring the error like so:

remove-item alias:cd -ea silentlycontinue

The -ea is short for ErrorAction.  Another type of problem might require that you only ever run a piece of script on the first time the script is run in the current shell.  One way to work around this problem is to create a global shell variable to keep track of the number of times the profile has been reloaded e.g.:

$global:__profileLoadCount += 1
if ($global:__profileLoadCount -eq 1) {
    $global:__cd_windowTitle = $host.ui.rawui.WindowTitle

This entry was posted in Monad. Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s