PowerShell Genie
Learn Profiles

PowerShell Profiles

Every PowerShell session can start with your setup already loaded. The $PROFILE script runs automatically at startup — your functions, aliases, module imports and prompt, ready before you type a thing.

Beginner 5 min read Works in Windows PowerShell 5.1 and PowerShell 7

Documentation: about_Profiles documentation

What a profile does

A profile is a script PowerShell runs for you, every time, before the first prompt appears. Anything in it — a function definition, an alias, a module import, a customized prompt, a default parameter value — is already in place when you start working.

There are four profiles, and $PROFILE knows them all. CurrentUserCurrentHost is the one most people mean: your account, the host you are actually running. AllUsersCurrentHost applies to everyone on the machine in that host. The two AllHosts variants run in every host, console and editor alike. The host matters: the console and VS Code have different CurrentHost profiles, so a function added to the console profile does not appear in VS Code.

By default, no profile file exists. PowerShell does not create one for you and does not complain that it is missing — Test-Path $PROFILE simply returns False until you make it.

See the objects move

Inspect this authored example with fictional data in the bounded browser model. The numbered stages show how its objects change.

New-Item -ItemType File -Path $PROFILE -Force
  1. Stage 1New-Item -ItemType File -Path $PROFILE -ForceTry it: make a profile function

    Create and edit your profile

    See the path, create the file if it is missing, then open it in an editor:

    1PS> $PROFILE
    2PS> Test-Path $PROFILE
    3PS> New-Item -ItemType File -Path $PROFILE -Force
    4PS> notepad $PROFILE

    A useful profile is short. A function you type daily, an alias for a long command, one or two module imports, and a prompt that shows what you need — nothing more. Every line in the profile runs at every startup, so a heavy profile makes every session start slowly:

    1PS> function Get-DiskFree { Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
    2PS> Select-Object DeviceID, @{N='FreeGB';E={[math]::Round($_.FreeSpace / 1GB, 1)}} }
    3PS> Import-Module Microsoft.PowerShell.Management -ErrorAction SilentlyContinue
    4PS> function prompt { "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " }

    One gate to remember: a profile is a script, so the execution policy applies to it. With the default Restricted policy, your profile never runs. RemoteSigned — the usual workstation setting — allows your own unsigned profile while blocking downloaded scripts.

    Try it: make a profile function

    Create the profile file, add one function, then start a fresh session and call it:

    1PS> New-Item -ItemType File -Path $PROFILE -Force
    2PS> Add-Content $PROFILE 'function ll { Get-ChildItem | Format-Table Name, Length }'
    3PS> powershell -NoExit -Command ll

    The last line starts a new session that loads the profile and immediately runs ll — proof the function survived into a fresh session. In PowerShell 7 the launcher is pwsh instead of powershell, and its CurrentHost profile path differs from 5.1, so check $PROFILE in each version you use.

    Common mistakes

    • Editing the wrong profile. $PROFILE shows four paths. Editing AllUsersCurrentHost when you meant CurrentUserCurrentHost either affects everyone or, edited as a non-admin, fails outright.
    • Profile never runs. Restricted execution policy blocks it silently. Set RemoteSigned for the current user and test with a fresh session.
    • Heavy imports at startup. Ten module imports and a network call in the profile make every session crawl. Import lazily, inside the functions that need the module.
    • Host-specific code in an AllHosts profile. A command that only exists in the console breaks VS Code startup when placed in CurrentUserAllHosts. Keep host-specific lines in that host's profile.
    • Assuming the profile exists. A fresh machine has no profile file. Scripts that append to $PROFILE must create it first with New-Item -Force.

    Your turn

    On your own machine, create your CurrentUserCurrentHost profile and add two things: a function that shows free disk space in GB, and a prompt that shows the current folder. Open a new session and confirm both work before you type anything else.

    Prove it: write it alone

    Blank editor. No starter, no hints. Write the commands that create your profile if missing, append a function named Get-Uptime to it, and verify the function exists in a brand-new session.

    Practise this

    Create your profile

    Create your profile and add a function that is available in every new session.

    Review the lesson

    Recap

    $PROFILE is four paths; CurrentUserCurrentHost is the one you usually edit. Create it with New-Item -Force, keep it short so sessions start fast, remember the execution policy gates it, and verify every change in a fresh session — the profile only proves itself at startup.

    Genie guidePowerShell Profiles

    The $PROFILE script runs automatically every time PowerShell starts. Put your functions, aliases and prompt in it — but keep it light, or every session starts slowly.

    Stuck? Re-read the section, then try the filter yourself.