Skip to content

Repository files navigation

My PowerShell profile

CI

My personal PowerShell profile, shared in case it's useful to others.

Contents

Prerequisites

  • Windows only. The profile assumes Windows paths (C:\...) and Windows-specific tools (devenv, rider64.exe, winget, Windows Terminal). It will not work as-is on macOS/Linux.
  • PowerShell 7.1 or later (i.e. pwsh, not Windows PowerShell 5.1). The profile uses the ?? null-coalescing operator and the .LinkTarget property on symlinks, neither of which exist in Windows PowerShell 5.1.
  • If you download the repo as a zip instead of git clone-ing it, Windows may block the .ps1 files as coming from the internet - run Get-ChildItem -Recurse *.ps1 | Unblock-File in the repo folder, and make sure your execution policy allows running local scripts (e.g. RemoteSigned).

Dependencies

Modules and scripts

None of these are hard requirements: each module/tool is imported defensively, so if something isn't installed, the profile prints a warning for that piece and keeps loading the rest.

Usage

Either

  • clone directly into your PowerShell profile directory, or,
  • clone in another directory, and setup a symlink to the path where PowerShell looks for your profile. I.e., in an elevated shell, from the cloned directory, do something like:
New-Item -Path $PROFILE -ItemType SymbolicLink -Value (Get-Item .\Microsoft.PowerShell_profile.ps1).FullName

Updating

Since it's just a git repo, pull the latest changes from wherever you cloned it:

git pull

Structure

Microsoft.PowerShell_profile.ps1 itself is just a small loader. The actual logic lives in profile.d/, loaded in filename order, one concern per file:

File Purpose
00-helpers.ps1 Shared helper functions (safe module import/dot-source, Test-IsElevated, etc.)
10-options.ps1 Config variables - utils path, outdated-check settings
20-modules.ps1 PSReadLine
30-aliases-and-tools.ps1 s, vs/OpenWithVisualStudio, rider/OpenWithRider, winutil
40-utils-import.ps1 Loads scripts from the dontrolle/Powershell utils repo
50-prompt-and-git.ps1 Get-ChildItemColor, l/ls aliases, oh-my-posh prompt
60-winget.ps1 winget tab-completion
70-banner-and-checks.ps1 Startup reminders banner + periodic winget upgradeable check
90-personal.ps1.example Example personal touch (starting directory) - not loaded automatically

Feel free to add, remove, reorder, or split these files further to fit your own setup.

Customization

  • Utils path: by default the profile looks for the dontrolle/Powershell utils repo at $Home\src\Powershell. Override this by setting $env:POWERSHELL_UTILS_PATH before the profile loads, or in profile.local.ps1 (see below).
  • profile.local.ps1: an optional, gitignored file in the repo root. If present, it is dot-sourced first, before anything in profile.d/, so it can pre-set any option variable used in profile.d/10-options.ps1 (e.g. $PowershellUtilsPath) as well as run arbitrary personal tweaks (e.g. a starting directory - see profile.d/90-personal.ps1.example) - all without editing tracked files.

Linting

The CI GitHub Actions workflow runs PSScriptAnalyzer (and the Pester tests, see Tests below) on every push/PR. Run the lint locally with:

Install-Module -Name PSScriptAnalyzer -Scope CurrentUser
Invoke-ScriptAnalyzer -Path . -Settings .\PSScriptAnalyzerSettings.psd1 -Recurse

Tests

Unit tests live under Tests/ and use Pester v5. They cover:

  • Tests/ScriptSyntax.Tests.ps1 - a syntax smoke test asserting every *.ps1 file parses cleanly.
  • Tests/Helpers.Tests.ps1 - _Test-DotSourceTarget from 00-helpers.ps1.
  • Tests/Aliases.Tests.ps1 - the .sln-resolution logic in OpenWithVisualStudio from 30-aliases-and-tools.ps1 (with Get-ChildItem/Start-Process mocked).

Run them locally with:

Install-Module -Name Pester -MinimumVersion 5.0.0 -Scope CurrentUser
Invoke-Pester -Path .\Tests

License

See LICENSE.

About

My PowerShell profile - uses a few modules such as Oh-My-Posh for customizing the PS prompt, and sources a few of my own modules and scripts. Developer-oriented. Usage instructions included.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages