PowerShell - Profile Custom Setup
Overview
Sources:
- **
Code
$PROFILE
# --------------------------------------------------------------
# PowerShell Core $PROFILE (Current User, All Hosts)
# --------------------------------------------------------------
# variables
$Global:Interactive = ($Host.Name -eq 'ConsoleHost')
$Global:ProfileRootPath = Split-Path -Path $PROFILE -Parent
$Global:ProfileSourcePath = Join-Path -Path $ProfileRootPath -ChildPath 'Source'
$Global:ProfileConfigPath = Join-Path -Path $ProfileSourcePath -ChildPath 'Profile.Configuration.psd1'
# remove "R" alias which by default is set to Invoke-History (for R.exe to work)
Remove-Alias -Name R -ErrorAction SilentlyContinue
# set ai alias
Set-Alias -Name ai -Value aichat.exe -ErrorAction SilentlyContinue
# import chocolatey profile
try {
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -ErrorAction Stop
} catch {
Write-Warning "Chocolatey profile not loaded: $_"
}
# azure-cli completion
if (Get-Command az -ErrorAction SilentlyContinue) {
Register-ArgumentCompleter -Native -CommandName az -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
try {
$completion_file = New-TemporaryFile
$env:ARGCOMPLETE_USE_TEMPFILES = 1
$env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file
$env:COMP_LINE = $wordToComplete
$env:COMP_POINT = $cursorPosition
$env:_ARGCOMPLETE = 1
$env:_ARGCOMPLETE_SUPPRESS_SPACE = 0
$env:_ARGCOMPLETE_IFS = "`n"
$env:_ARGCOMPLETE_SHELL = 'powershell'
az 2>&1 | Out-Null
Get-Content $completion_file | Sort-Object | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
Remove-Item $completion_file -ErrorAction SilentlyContinue
Remove-Item Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL -ErrorAction SilentlyContinue
} catch {
Write-Warning "Error in az completion: $_"
}
}
}
# gh-cli completion
if (Get-Command gh -ErrorAction SilentlyContinue) {
try {
Invoke-Expression -Command $(gh completion --shell powershell | Out-String)
Write-Verbose 'GitHub CLI shell completion registered successfully.'
} catch {
Write-Warning "Failed to register GitHub CLI shell completion: $_"
}
}
# aichat completion & shell integration
if (Get-Command aichat -ErrorAction SilentlyContinue) {
try {
. (Join-Path $ProfileSourcePath 'Completions\aichat.completion.ps1')
Write-Verbose 'aichat shell completion registered successfully.'
Set-PSReadLineKeyHandler -Chord 'alt+e' -ScriptBlock {
$_old = $null
[Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$_old, [ref]$null)
if ($_old) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('⌛')
$_new = (aichat -e $_old)
[Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine()
[Microsoft.PowerShell.PSConsoleReadline]::Insert($_new)
}
}
Write-Verbose 'aichat shell integration registered successfully.'
} catch {
Write-Warning "Failed to register aichat shell completion: $_"
}
}
# obsidian-cli completion & alias
if (Get-Command obsidian-cli -ErrorAction SilentlyContinue) {
try {
. (Join-Path $ProfileSourcePath 'Completions\obs.completion.ps1')
Write-Verbose 'Obsidian CLI shell completion registered successfully.'
} catch {
Write-Warning "Failed to register Obsidian CLI shell completion: $_"
}
# obs_cd() {
# local result=$(obsidian-cli print-default --path-only)
# [ -n "$result" ] && cd -- "$result"
# }
Function obscd {
$result = (obsidian-cli print-default --path-only)
if ($result) {
Set-Location $result
} else {
Write-Warning 'Failed to get Obsidian default path'
}
}
}
# zoxide initialization
try {
if (Get-Command zoxide -ErrorAction SilentlyContinue) {
Invoke-Expression (& { (zoxide init powershell --cmd z | Out-String) })
}
} catch {
Write-Warning "Zoxide not initialzied: $_"
}
# oh-my-posh initialization
try {
if (Get-Command oh-my-posh -ErrorAction SilentlyContinue) {
$themeFile = Join-Path "$Env:POSH_THEMES_PATH" 'wopian.omp.json' -ErrorAction SilentlyContinue
if (Test-Path $themeFile -ErrorAction SilentlyContinue) {
$Expression = (& oh-my-posh init pwsh --config=$themeFile --print) -join "`n"
Invoke-Expression $Expression
} else {
Write-Warning "Theme file not found: $themeFile"
}
}
} catch {
Write-Warning "Oh-My-Posh not initialized: $_"
}
# PSReadLine
Set-PSReadLineKeyHandler -Key Ctrl+Home -Function BeginningOfLine
Set-PSReadLineKeyHandler -Key Ctrl+End -Function EndOfLine
Set-PSReadLineKeyHandler -Key Ctrl+Shift+Home -Function SelectBackwardsLine
Set-PSReadLineKeyHandler -Key Ctrl+Shift+End -Function SelectLine
# Functions
. $PSScriptRoot\Source\Public\Update-WinGetPackages.ps1
# Import modules
@(
'Microsoft.PowerShell.ConsoleGuiTools',
'Terminal-Icons',
'posh-git',
'F7History',
'tiPS'
) | ForEach-Object {
Import-Module $_ -ErrorAction SilentlyContinue
}
Components
Note: This reference is generated from the PowerShell profile codebase as of June 11, 2025. Functions are organized by category for easy navigation and reference. Each function includes a brief description of its purpose and functionality.
For detailed usage information, parameter details, and examples, refer to the individual function definitions in the source code or use Get-Help <FunctionName> in PowerShell.
Custom Functions
Profile Management Functions
Write-ProfileLog- Logging functionality for profile operationsInitialize-DebugLog- Sets up debug loggingMeasure-ProfileBlock- Performance measurement for profile componentsInvoke-ProfileReload- Reloads the PowerShell profileEdit-PSProfile- Opens profile for editingEdit-PSProfileProject- Opens profile project in editor
Lazy Loading & Performance
Register-LazyCompletion- Registers lazy-loaded tab completionsRegister-LazyModule- Registers lazy-loaded modulesGlobal:TabExpansion2- Custom tab expansion handlerMeasure-ScriptBlock- Measures script block execution time
Directory Navigation
Set-LocationParent- Navigate to parent directory (..)Set-LocationRoot- Navigate to root directorySet-LocationHome- Navigate to home directorySet-LocationBin- Navigate to user’s bin directorySet-LocationTools- Navigate to user’s tools directorySet-LocationTemp- Navigate to temporary directorySet-LocationConfig- Navigate to configuration directorySet-LocationOneDrive- Navigate to OneDrive directorySet-LocationDotFiles- Navigate to dotfiles directorySet-LocationDesktop- Navigate to desktopSet-LocationDownloads- Navigate to downloadsSet-LocationDocuments- Navigate to documentsSet-LocationPictures- Navigate to picturesSet-LocationMusic- Navigate to musicSet-LocationVideos- Navigate to videosSet-LocationDevDrive- Navigate to development drive
Navigation Aliases
Documents- Quick navigation to Documents folderDesktop- Quick navigation to Desktop folderDownloads- Quick navigation to Downloads folderTemp- Quick navigation to temp foldercd...- Go up two directory levelscd....- Go up three directory levelsHKLM:- Navigate to HKEY_LOCAL_MACHINE registryHKCU:- Navigate to HKEY_CURRENT_USER registryEnv:- Navigate to environment variables
System Utilities
Get-PublicIP- Retrieves public IP addressGet-Timestamp- Gets current timestampGet-RandomPassword- Generates random passwordsGet-SystemUptime- Gets system uptime informationGet-PCUptime- Gets PC uptimeGet-PCInfo- Gets comprehensive PC informationGet-WindowsBuild- Gets Windows build informationGet-IPv4NetworkInfo- Gets IPv4 network informationGet-ProcessUsingPort- Finds processes using specific portsGet-Printers- Lists available printersGet-RebootLogs- Gets system reboot logs
Environment Management
Get-EnvironmentVariables- Gets environment variables with analysisGet-EnvVarsFromScope- Gets environment variables from specific scopeExpand-PathVariable- Expands PATH variable entriesCompare-PathVariables- Compares PATH variables across scopesUpdate-Environment- Updates entire environmentUpdate-SessionEnvironment- Updates session environment variables
File Operations
Get-FolderSize- Gets folder size informationGet-FileOwner- Gets file ownership informationGet-ChildItemColor- Enhanced directory listing with colorsGet-SourceCode- Downloads source code from repositories
Hash Functions
Get-MD5Hash- Calculates MD5 hashGet-SHA1Hash- Calculates SHA1 hashGet-SHA256Hash- Calculates SHA256 hash
Application Management Functions
Get-Applications- Lists installed applicationsRemove-Application- Removes applicationsStart-GitKraken- Starts GitKraken applicationStart-RStudio- Starts RStudio applicationInvoke-Notepad- Opens Notepad
Package Management Functions
Update-Chocolatey- Updates Chocolatey packagesUpdate-Scoop- Updates Scoop packagesUpdate-Python- Updates Python packagesUpdate-Node- Updates Node.js packagesUpdate-R- Updates R packagesUpdate-Pip- Updates Pip packagesUpdate-Windows- Updates WindowsUpdate-WinGet- Updates WinGetUpdate-PSModules- Updates PowerShell modulesUpdate-AllPSResources- Updates all PowerShell resources
Module Management Functions
Get-DuplicatePSModules- Finds duplicate PowerShell modulesUninstall-DuplicatePSModules- Removes duplicate modulesGet-DynamicAboutHelp- Gets dynamic help content
System Administration Functions
Test-AdminRights- Tests for administrative privilegesInvoke-Admin- Runs commands as administratorMount-DevDrive- Mounts development driveReset-NetworkStack- Resets network stackReset-NetworkAdapter- Resets network adapterRemove-TempFiles- Removes temporary filesSet-PowerPlan- Sets power planStop-SelectedProcess- Stops selected processesInvoke-TakeOwnership- Takes ownership of files/foldersInvoke-TakeOwnershipWindowsApps- Takes ownership of Windows appsInvoke-DISM- Runs DISM operationsInvoke-SFC- Runs System File CheckerGet-SFCLogs- Gets SFC logsInvoke-CheckDisk- Runs check diskGet-WinSAT- Gets Windows System Assessment Tool results
Helper Functions
Import-Completion- Imports tab completionsImport-AliasFile- Imports alias filesSearch-History- Searches command historyGet-GitHubRateLimits- Gets GitHub API rate limitsRemove-GitHubWorkflowRuns- Removes GitHub workflow runsWrite-OperationStatus- Writes operation status messagesInvoke-EnvVarAIAnalysis- AI analysis of environment variables
Testing Utility Functions
Test-Internet- Tests internet connectivityTest-Admin- Tests administrative privilegesTest-Command- Tests if commands existTest-ServiceRunning- Tests if services are runningTest-PSGallery- Tests PowerShell Gallery connectivityTest-SSHKey- Tests SSH key functionalityTest-GPGKey- Tests GPG key functionalityTest-Email- Tests email functionality
System Optimization Functions
Optimize-DefenderExclusions- Optimizes Windows Defender exclusionsRemove-OldDrivers- Removes old driversClean-ProfileRepository- Cleans profile repository
Installation Functions
Install-OhMyPosh- Installs Oh My PoshInstall-NerdFont- Installs Nerd Fonts
Aliases
Development Aliases
@{
'ib' = 'Invoke-Build'
'test' = 'Invoke-Pester'
'pester' = 'Invoke-Pester'
'psake' = 'Invoke-PSake'
'psdeploy' = 'Invoke-PSDeploy'
'deps' = 'Invoke-PSDepend'
'reqs' = 'Invoke-PSDepend'
'lint' = 'Invoke-PSScriptAnalyzer'
'lintfix' = 'Invoke-PSScriptAnalyzerFix'
'reload' = 'Restart-PSSession'
'editprof' = 'Edit-PSProfile'
'editprofdir' = 'Edit-PSProfileDirectory'
'reloadprof' = 'Reload-PSProfile'
'help' = 'Get-Help'
'dynhelp' = 'Get-DynamicAboutHelp'
}Navigation Aliases
@{
'Home' = 'Set-LocationHome'
'~' = 'Set-LocationHome'
'Desktop' = 'Set-LocationDesktop'
'Downloads' = 'Set-LocationDownloads'
'Documents' = 'Set-LocationDocuments'
'Pictures' = 'Set-LocationPictures'
'Music' = 'Set-LocationMusic'
'Videos' = 'Set-LocationVideos'
'DevDrive' = 'Set-LocationDevDrive'
'Dotfiles' = 'Set-LocationDotFiles'
'OneDrive' = 'Set-LocationOneDrive'
'Tools' = 'Set-LocationTools'
'Bin' = 'Set-LocationBin'
'Config' = 'Set-LocationConfig'
'Ubuntu' = 'Set-LocationWSL'
'Dots' = 'Set-LocationDotFiles'
}
Program Aliases
@{
'np' = (Get-Command -Name 'notepad.exe').Source
'expl' = (Get-Command -Name 'explorer.exe').Source
'calc' = (Get-Command -Name 'calc.exe').Source
'gkrak' = (Get-Command -Name 'gitkraken.cmd').Source
'codee' = (Get-Command -Name 'code-insiders.cmd').Source
'r' = (Get-Command -Name 'R.bat').Source
'rscript' = (Get-Command -Name 'R.bat').Source
'rstudio' = 'Start-RStudio'
'krak' = 'Start-GitKraken'
}
System Aliases
@{
'reboot' = 'Restart-Computer'
}
Completions
AWS CLI
If (Get-Command aws -ErrorAction SilentlyContinue) {
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$env:COMP_LINE = $wordToComplete
$env:COMP_POINT = $cursorPosition
aws_completer.exe | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
Remove-Item Env:\COMP_LINE
Remove-Item Env:\COMP_POINT
}
}bat
If (Get-Command bat -ErrorAction SilentlyContinue) {
Invoke-Expression -Command $(bat --completion ps1 | Out-String)
}Configuration
Default Parameters
Modules
PSReadLine
Other
Appendix
Note created on 2025-12-25 and last modified on 2025-12-25.
See Also
Backlinks
(c) No Clocks, LLC | 2025