The PowerShell profile is the heart of your customized shell experience, loading modules, functions, and configurations on startup.
Location: Deployed to $PROFILE (typically ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1)
Source: PowerShell/Microsoft.PowerShell_profile.ps1
Features:
- Deferred module loading for fast startup
- Auto-discovery of custom modules
- oh-my-posh initialization
- Argument completers
- Custom functions
- UTF-8 encoding
# Deferred module loading
Register-EngineEvent PowerShell.OnIdle -Action {
# Load modules after shell is ready
}Modules load in the background after PowerShell starts, ensuring fast startup times.
oh-my-posh init pwsh --config "path\to\theme.omp.json" | Invoke-ExpressionLoads your custom prompt theme.
Deferred loading:
- PSFzf
- Terminal-Icons
- posh-git
- F7History
Immediate loading:
- Custom modules from
IncludedModules/ - Custom modules from
CustomModules/(auto-discovered)
Launch Yazi with directory change capability:
function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi $args --cwd-file="$tmp"
$cwd = Get-Content -Path $tmp
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
Set-Location -LiteralPath $cwd
}
Remove-Item -Path $tmp
}Remove bin/obj directories recursively:
function clean {
Get-ChildItem -Include bin,obj -Recurse -Directory |
Remove-Item -Recurse -Force
}Open Visual Studio solution files:
function Open-Solution {
param([string]$SolutionPath)
# Opens .sln in Visual Studio
}Located in PowerShell/IncludedModules/:
utilities.psm1- General helper functionsbuild_functions.psm1- Build-related utilities
Usage:
# These are automatically loaded by the profile
# Functions are immediately availableLocated in PowerShell/CustomModules/:
Auto-discovery: Any .psm1 file in this directory is automatically imported.
Example:
# PowerShell/CustomModules/my-tools.psm1
function Get-MyTool {
[CmdletBinding()]
param([string]$Name)
Write-Host "Running tool: $Name"
}
Export-ModuleMember -Function Get-MyToolThis function is automatically available in new PowerShell sessions.
For customizations that shouldn't be in version control:
# Create from template
Copy-Item "$HOME\Documents\PowerShell\CustomProfile.ps1.template" `
"$HOME\Documents\PowerShell\CustomProfile.ps1"
# Edit
code "$HOME\Documents\PowerShell\CustomProfile.ps1"What to add:
- Personal aliases
- Environment variables
- Additional module imports
- Company-specific configurations
Example CustomProfile.ps1:
# Personal aliases
Set-Alias -Name g -Value git
Set-Alias -Name v -Value vim
# Environment variables
$env:MY_VAR = "value"
# Additional modules
Import-Module MyCompanyModule
# Custom functions
function Start-MyWorkflow {
# Your workflow
}This file is git-ignored and won't be overwritten by updates.
The profile registers completers for:
- winget - Package names and commands
- dotnet - .NET CLI commands
- git - Git commands (via posh-git)
UTF-8 encoding is set by default:
[console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()This ensures proper handling of Unicode characters.
Smart directory navigation:
Invoke-Expression (& { (zoxide init powershell | Out-String) })Enables the z command for jumping to frequently-used directories.
Enhanced command-line editing:
- Predictive IntelliSense
- History-based suggestions
- Syntax highlighting
- Custom key bindings
After making changes:
# Reload profile
. $PROFILEOr restart PowerShell.