Note: While these customizations work with PowerShell 5.1 (Windows default), upgrading to PowerShell 7+ is highly recommended for:
- Better module compatibility
- Improved performance
- Modern features and syntax
- Fewer compatibility issues
- Better error handling
$PSVersionTable.PSVersion
If you want to upgrade (recommended):
winget install --id Microsoft.PowerShell --source winget
Windows 11 can have multiple PowerShell versions installed simultaneously:
- Windows PowerShell 5.1 (Default Windows version)
- Located at:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- Default profile paths:
- Located at:
# PowerShell 5.1 Profile Locations
AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\$env:USERNAME\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\$env:USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
- PowerShell 7+ (Modern version)
- Located at:
C:\Program Files\PowerShell\7\pwsh.exe
- Default profile paths:
- Located at:
# PowerShell 7+ Profile Locations
AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1
AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\$env:USERNAME\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\$env:USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
When using OneDrive with Documents folder sync:
- The
Documents
paths will be redirected toC:\OneDrive\Documents\
- Example for PowerShell 5.1:
CurrentUserAllHosts : C:\OneDrive\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
- Example for PowerShell 7:
CurrentUserAllHosts : C:\OneDrive\Documents\PowerShell\profile.ps1
CurrentUserCurrentHost : C:\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
- Check PowerShell version:
$PSVersionTable.PSVersion
- View your profile locations:
$PROFILE | Select-Object *Host* | Format-List
- Each PowerShell version maintains its own separate profile files
- OneDrive sync can affect profile locations
- You may need to configure both profiles if using both PowerShell versions
- Some features (like PSReadLine prediction) are only available in PowerShell 7+
- Use
$env:USERNAME
to get your actual username in paths
Different PowerShell versions require different PSReadLine configurations:
# Check current version
Get-Module -Name PSReadLine -ListAvailable | Select-Object -Property Name,Version
# Update to latest version
Install-Module PSReadLine -Force -SkipPublisherCheck
# Configuration in profile
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
# Check current version
Get-Module -Name PSReadLine -ListAvailable | Select-Object -Property Name,Version
# Update to latest version that supports 5.1
Install-Module -Name PSReadLine -AllowPrerelease -Force -SkipPublisherCheck
# Configuration in profile (basic features only)
Set-PSReadLineOption -EditMode Windows
# Note: PredictionSource and PredictionViewStyle are not available in older versions
winget install JanDeDobbeleer.OhMyPosh -s winget
Install via Oh My Posh:
oh-my-posh font install
Recommended fonts:
- CascadiaCode
- CaskaydiaCove NF
- CaskaydiaCove NFP
- CaskaydiaCove NFM
- FiraCode
- FiraCode Nerd Font Propo
- FiraCode Nerd Font
- FiraCode Nerd Font Mono
- Meslo
- MesloLGM Nerd Font
- MesloLGS Nerd Font
- Other Meslo variants
Install-Module -Name Terminal-Icons -Repository PSGallery
- Posh-Git for Git integration
- Z module for directory navigation:
Install-Module z -AllowClobber
Create/edit your PowerShell profile:
notepad $PROFILE
Add these configurations:
# Oh My Posh initialization
oh-my-posh --init --shell pwsh --config C:\Users\YourUsername\AppData\Local\Programs\oh-my-posh\themes\jandedobbeleer.omp.json | Invoke-Expression
# Enable modules
$env:POSH_GIT_ENABLED = $true
Import-Module -Name Terminal-Icons
Import-Module z
# PSReadLine configuration
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
Add this to your Windows Terminal settings:
"profiles": {
"defaults": {
"font": {
"face": "MesloLGM Nerd Font"
}
}
}
After setup, verify your installation:
- PowerShell version:
$PSVersionTable.PSVersion
- Execution policy:
Get-ExecutionPolicy
- PSReadLine:
Get-Module PSReadLine
-
Module Compatibility
- Some newer modules might not work correctly
- You may see warnings about compatibility
- Some features might be limited or unavailable
-
Performance Issues
- Slower command prediction
- Limited parallel processing capabilities
-
PSReadLine Limitations
- Some newer prediction features might not work
- Limited syntax highlighting capabilities
- If you encounter execution policy errors:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
-
If modules fail to import:
- Try running PowerShell as administrator when installing modules
- Check module compatibility with your PowerShell version
- Clear PowerShell module cache if needed
-
Font issues:
- Restart Windows Terminal after installing new fonts
- Verify font installation in Windows Fonts settings
- Check for correct font name in terminal settings
PowerToys' Command Not Found feature helps suggest package installations when you type an unrecognized command in PowerShell. For example, if you type node
but don't have Node.js installed, it suggests installing it via winget.
If you see this error:
Import-Module: The specified module 'C:\Users\[username]\AppData\Local\PowerToys\WinUI3Apps\..\WinGetCommandNotFound.psd1' was not loaded because no valid module file was found in any module directory.
- PowerToys version 0.70.0 or later
- Windows 10 version 1903 (build 18362) or later
- PowerShell 5.1 or later
- Winget installed and configured
- PowerToys installation issues
- Module file has been moved or deleted
- Compatibility issues with PowerShell 7
- Experimental features not enabled
- Incorrect path references in PowerShell profile
- Verify PowerToys Installation
# Check if the module exists
Test-Path "C:\Users\$env:USERNAME\AppData\Local\PowerToys\WinGetCommandNotFound.psd1"
- Enable Required Features in PowerToys
- Open PowerToys Settings
- Navigate to 'Command Not Found'
- Enable the feature
- Restart PowerShell
- Enable PowerShell Experimental Features
Enable-ExperimentalFeature PSCommandNotFoundSuggestion
Enable-ExperimentalFeature PSFeedbackProvider
# Restart PowerShell after enabling features
- Fix Profile Configuration Edit your PowerShell profile:
notepad $PROFILE
Add this safer conditional import:
# PowerToys Command Not Found Integration
$powerToysModulePath = Join-Path $env:LocalAppData "PowerToys\WinGetCommandNotFound.psd1"
if (Test-Path $powerToysModulePath) {
Import-Module $powerToysModulePath
}
- Manual Module Installation If other solutions fail:
- Download PowerToys from GitHub Releases
- Run installer as administrator
- Enable Command Not Found in PowerToys settings
- Restart PowerShell
If experiencing slow profile loading:
# Measure specific module load time
Measure-Command { Import-Module ModuleName }
# Profile load time optimization tips
# 1. Use conditional imports
# 2. Remove unused modules
# 3. Consider async loading for non-critical modules
After setup, you can test the feature:
- Try running a non-existent command that has a known package
python
# Should suggest installing Python if not installed
- Verify module is loaded correctly:
Get-Module WinGetCommandNotFound
- PowerToys Command Not Found Documentation
- PowerToys GitHub Repository
- WinGet Command Not Found GitHub Repository
- Oh My Posh Documentation
- Terminal Icons Repository
- Scott Hanselman's Terminal Customization Guide
- PowerShell Documentation
- PSReadLine Parameter Errors in PowerShell 5.1 If you see errors like:
Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'PredictionSource'.
This means you're using PowerShell 5.1 with modern PSReadLine features. Solutions:
- Remove the unsupported parameters from your 5.1 profile
- Upgrade to PowerShell 7+ for full feature support
- Use conditional logic in your profile:
if ($PSVersionTable.PSVersion.Major -ge 7) {
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
}
Set-PSReadLineOption -EditMode Windows
You can store your PowerShell profiles in a custom location and create symbolic links to the default locations. Here's how:
- Create a Git Repository
# Create a directory for your profiles
mkdir C:\Users\YourUsername\Documents\PowerShellProfiles
cd C:\Users\YourUsername\Documents\PowerShellProfiles
# Initialize git
git init
- Create Profile Files
# Create separate profiles for PS 5.1 and PS 7
New-Item -ItemType File -Path ".\Microsoft.PowerShell_profile.ps1" # For PS 5.1
New-Item -ItemType File -Path ".\Microsoft.PowerShell_profile.pwsh.ps1" # For PS 7
- Create Symbolic Links
# For PowerShell 5.1
New-Item -ItemType SymbolicLink -Path "$env:OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -Target "C:\Users\YourUsername\Documents\PowerShellProfiles\Microsoft.PowerShell_profile.ps1"
# For PowerShell 7
New-Item -ItemType SymbolicLink -Path "$env:OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -Target "C:\Users\YourUsername\Documents\PowerShellProfiles\Microsoft.PowerShell_profile.pwsh.ps1"
- Create .gitignore
# Create .gitignore
@"
# Local PowerShell files
*.log
*.tmp
# Module caches
**/Modules/*
"@ | Out-File .gitignore
- Initial Commit
git add .
git commit -m "Initial PowerShell profile setup"
- Add Remote Repository
git remote add origin https://github.com/YourUsername/powershell-profiles.git
git push -u origin main
- Version control for your profiles
- Easy synchronization across machines
- Backup of your configurations
- Ability to share configurations with others
- Track changes and rollback if needed
- Make sure to not commit sensitive information
- Consider using environment variables for machine-specific settings
- Use conditional logic for OS-specific configurations
- Keep module installations separate from profile configurations