Search code examples
powershellpowershell-corewindows-terminal

Windows Terminal - Launch powershell with different profile


How can I configure windows terminal to launch Powershell with a separate profile other than my standard $Profile?


This would be helpful to have import modules like posh-git and psreadline only in the Powershell instance that I launch from wt.exe rather than from pwsh.exe


Solution

  • You can source a custom Powershell (.ps1) profile file as you invoke pwsh.exe or powershell.exe from wt.exe. For example a posh-git profile in Windows Terminal settings.json Would look something like this:

    {
        "guid": "{01463d52-dda9-4109-b03f-c55899b52df2}",
        "name": "Powershell - Posh Git",
        "commandline": "powershell.exe -noprofile -noexit -command \"invoke-expression '. ''C:/PsProfilePoshGit.ps1''' \"",
        "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
        "hidden": false
    },
    
    

    You can generate a unique guid for each new profile you add by running the command [guid]::NewGuid() in Powershell.

    Finally your dedicated Powershell profile file: C:/PsProfilePoshGit.ps1 would look something like this (at a minimum):

    Import-Module posh-git
    function global:prompt
    {
        Write-Host -Object "Posh-Git" -NoNewline -ForegroundColor Magenta
     
        return "> "
    }