PowerShell Setup¶
This guide covers PowerShell installation, configuration, and module management on macOS.
Overview¶
PowerShell provides a powerful cross-platform scripting environment with: - Advanced cmdlets and pipeline support - Object-oriented command output - Module system for extensibility - Integration with .NET and macOS APIs - Consistent experience across platforms
Installation¶
PowerShell is automatically installed via the run_once_install-powershell.sh.tmpl script when you apply your dotfiles.
Manual Installation¶
If needed, you can install PowerShell manually:
Verify installation:
Profile Configuration¶
The PowerShell profile is located at:
- Template: dot_config/powershell/Microsoft.PowerShell_profile.ps1.tmpl
- Installed: ~/.config/powershell/Microsoft.PowerShell_profile.ps1
Profile Features¶
Module Imports¶
The profile automatically imports essential modules:
# Enhanced readline functionality
Import-Module PSReadLine
# Git integration
Import-Module posh-git
# Custom prompt themes
Import-Module oh-my-posh
# File/folder icons
Import-Module Terminal-Icons
# Fuzzy finder integration
Import-Module PSFzf
Custom Prompt¶
The profile configures oh-my-posh for a beautiful, informative prompt:
Aliases and Functions¶
Common aliases for productivity:
# Directory navigation
Set-Alias -Name ll -Value Get-ChildItem
# Git shortcuts
Set-Alias -Name g -Value git
# System utilities
function which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path
}
Module Management¶
PowerShell modules are defined in .chezmoidata/powershell.yaml and automatically managed.
Installed Modules¶
The configuration includes these essential modules:
PSReadLine¶
Enhanced command-line editing with: - Syntax highlighting - Multi-line editing - History searching - Predictive IntelliSense
posh-git¶
Git integration providing: - Git status in prompt - Tab completion for Git commands - Branch information display
oh-my-posh¶
Customizable prompt themes: - Cross-platform consistency - Rich segment customization - Git status visualization - Execution time tracking
Terminal-Icons¶
Visual file/folder icons in listings:
- Color-coded by file type
- Instant visual recognition
- Works with Get-ChildItem
PSFzf¶
Fuzzy finder integration:
- Ctrl+T - Find files
- Ctrl+R - Search history
- Alt+C - Change directory
Az Module Suite¶
Azure management modules:
- Az.Accounts - Authentication
- Az.Resources - Resource management
- Az.Storage - Storage operations
- Az.KeyVault - Secrets management
- Az.Compute - VM management
Microsoft.Graph¶
Microsoft 365 and Azure AD: - User management - Group operations - Intune administration - Conditional Access policies
Other Modules¶
- PSIntuneAuth - Intune authentication
- IntuneWin32App - App packaging
- Pester - Testing framework
- PSScriptAnalyzer - Code quality
Adding New Modules¶
-
Edit the module list:
-
Add your module:
-
Apply changes:
The module will be automatically installed.
Updating Modules¶
Modules are automatically updated when you run chezmoi apply if the configuration changes.
To manually update all modules:
To update a specific module:
Module Configuration¶
PSReadLine Configuration¶
Customize in your profile:
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
oh-my-posh Themes¶
List available themes:
Change theme:
Make it permanent by updating your profile.
PSFzf Configuration¶
Customize keybindings:
Common Tasks¶
Running Scripts¶
Execute a PowerShell script:
With parameters:
Azure Management¶
Connect to Azure:
List resources:
Microsoft Graph¶
Connect:
Get users:
Troubleshooting¶
Execution Policy¶
If you can't run scripts:
Module Import Errors¶
Check if module is installed:
Import manually:
Profile Not Loading¶
Check profile path:
Reload profile:
Module Installation Failed¶
Clear package cache:
Install module manually:
Oh-my-posh Not Working¶
Verify installation:
Reinstall if needed:
Best Practices¶
- Keep Modules Updated - Run
Update-Moduleregularly - Use Virtual Environments - Isolate project dependencies
- Test Scripts - Use Pester for script testing
- Follow Style Guide - Use PSScriptAnalyzer
- Secure Credentials - Use SecureString and credential management
- Error Handling - Always use try/catch blocks
- Comment Code - Use comment-based help for functions