This is a little bit fancy... but it works:
Step 1: Create a Powershell Profile:
FILE: install_profile.ps1
# THIS SCRIPT BLOWS AWAY YOUR DEFAULT POWERSHELL PROFILE SCRIPT
# AND INSTALLS A POINTER TO A GLOBAL POWERSHELL PROFILE
$ErrorActionPreference = "Stop"
function print ([string]$msg)
{
Write-Host -ForegroundColor Green $msg
}
print ""
# User's Powershell Profile
$psdir = "$env:USERPROFILE\Documents\WindowsPowerShell"
$psfile = $psdir + "\Microsoft.PowerShell_profile.ps1"
print "Creating Directory: $psdir"
md $psdir -ErrorAction SilentlyContinue | out-null
# this is your auto-generated powershell profile to be installed
$content = @(
"",
". ~/Documents/tools/profile.ps1",
""
)
print "Creating File: $psfile"
[System.IO.File]::WriteAllLines($psfile, $content)
print ""
# Make sure Powershell profile is readable
Set-ExecutionPolicy -Scope CurrentUser Unrestricted
Step 2: then in tools ~/Documents/tools/profile.ps1:
function Do-ActualThing {
# do actual thing
}
Set-Alias MyAlias Do-ActualThing
Step 3:
$ Set-ExecutionPolicy -Scope CurrentUser Unrestricted $ . ./install_profile.ps1