I’ve seen a lot of people post their personal PowerShell profile scripts online for others to peruse, so I figured I’d do the same. You can also view the most current copy in my Git repository.

As is usually the case with things like this, this script is a work-in-progress. As such, I will try to edit this entry any time I make a modification to it.

LAST EDIT 27-May-2010: Edited this post because there are some things I just don’t do anymore, and updated the script yet again. If you’re looking for the latest-and-greatest, I would check the Git repo, because I have a habit of not updating this post.

################################################################################
# 
# $Id: Microsoft.PowerShell_profile.ps1 196 2010-05-28 01:59:30Z seth $
# 
# DESCRIPTION:  PowerShell personal profile.
#
# Copyright (c) 2009 Seth Wright (wrightst@jmu.edu)
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
################################################################################

# Add any other paths to search for scripts here.
$ExtraScriptPaths = "~/PowerShellScripts"

Write-Host -Fore Cyan ($MyInvocation.MyCommand).Definition
Write-Host

# Add all registered snapins.
foreach ($Snapin in ( Get-PSSnapin -registered )) {
    Add-PSSnapin $Snapin
    Write-Host "Added Snapin " -NoNewLine
    Write-Host $Snapin.Name -Fore Green
}


# Loop through the PowerShellScripts folder and execute all .ps1 files.
foreach ($ScriptFolder in $ExtraScriptPaths) {
    if (Test-Path $ScriptFolder) {
        $ScriptFolder = Resolve-Path $ScriptFolder
        Write-Host "Executing scripts found in $ScriptFolder..."
        foreach ( $script in (dir -Recurse $ScriptFolder | where { $_.Name -like "*.ps1" }) ) {
            Write-Host "Executing " -NoNewLine
            Write-Host $script.Name -Fore Red
            &($script.FullName)
        }
    } else {
        Write-Warning "Script Path `"$ScriptFolder`" does not exist."
    }
}


# Allow Unix-like functionality with the 'cd' command.
# First, remove the default "cd" alias
if (Test-Path Alias:\cd) { Remove-Item Alias:\cd }
function cd($path=$(Get-Item Env:UserProfile).Value) {
    if ($path) {
        Set-Location $path
    }
}

function prompt {
    $host.UI.RawUI.WindowTitle = "PowerShell: $pwd"
    Write-Host "PS" -NoNewLine -fore DarkGreen
    Write-Host (" " + $(get-location) + ">" + $(if ($nestedpromptlevel -ge 1) { ">>" }) ) -Fore DarkCyan -NoNewLine
    return " "
}

# Other aliases because I'm lazy.
function  npr   { notepad.exe $profile }

# Blank line before initial prompt.
Write-Host ""

# Remove any transient variables from the environment.
If (Test-Path Variable:\Snapin) { Remove-Variable Snapin }
If (Test-Path Variable:\script) { Remove-Variable script }
If (Test-Path Variable:\ExtraScriptPaths) { Remove-Variable ExtraScriptPaths }
If (Test-Path Variable:\ScriptFolder) { Remove-Variable ScriptFolder }

Send me an email or comment or whatnot if you have any questions, or if you have any suggestions for improvements!