Overview

This guide shows how to properly configure IntelliJ IDEA to load PowerShell profiles, environment variables, and Chocolatey modules when opening terminals or external tools.

Problem

By default, IntelliJ’s integrated have problem loading powershell profiles due to system path not being entirely set (truncated) :

  • PowerShell profiles ($PROFILE)
  • Chocolatey profile and modules
  • Updated environment variables (like cleaned PATH)

Solutions

1. Configure IntelliJ Built-in Terminal

Location: File → Settings → Tools → Terminal

Set Shell path to:

pwsh.exe -NoExit -Command "& {Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -ErrorAction SilentlyContinue; if(Test-Path $PROFILE){. $PROFILE}; refreshenv; Clear-Host}"

What this does:

  • Uses PowerShell 7+ (pwsh.exe)
  • Loads Chocolatey profile and modules
  • Loads your personal PowerShell profile
  • Refreshes environment variables
  • Clears screen for clean start
  • Keeps terminal open after initialization

2. Create External PowerShell Tool

Location: File → Settings → Tools → External Tools → + (Add)

Basic Settings:

  • Name: Open PowerShell Here
  • Description: Open PowerShell in current project directory
  • Group: Terminal Tools

Tool Settings:

  • Program: pwsh.exe
  • Arguments:
-NoExit -Command "& {Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -ErrorAction SilentlyContinue; if(Test-Path $PROFILE){. $PROFILE}; refreshenv; Set-Location '$ProjectFileDir$'; Clear-Host}"
  • Working directory: $ProjectFileDir$

3. Create PowerShell Admin Tool (for PATH cleanup)

Tool Settings:

  • Name: PowerShell Admin Here
  • Program: pwsh.exe
  • Arguments:
-Command "Start-Process pwsh -Verb RunAs -ArgumentList '-NoExit', '-Command', '& {Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -ErrorAction SilentlyContinue; if(Test-Path $PROFILE){. $PROFILE}; refreshenv; Set-Location ''$ProjectFileDir$''; Clear-Host}'"

4. Alternative: Custom Launcher Script

Create a batch file for consistent PowerShell launching:

File: C:\Users\[username]\intellij-pwsh.bat

@echo off
pwsh.exe -NoExit -Command "& {Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 -ErrorAction SilentlyContinue; if(Test-Path $PROFILE){. $PROFILE}; refreshenv; Clear-Host}"

Then use the batch file path in IntelliJ Terminal settings.

Command Breakdown

ComponentPurpose
pwsh.exePowerShell 7+ executable
-NoExitKeep terminal open after commands
-CommandExecute script block
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1Load Chocolatey modules
-ErrorAction SilentlyContinueDon’t fail if Chocolatey not installed
if(Test-Path $PROFILE){. $PROFILE}Load personal PowerShell profile
refreshenvRefresh environment variables
Set-Location '$ProjectFileDir$'Navigate to project directory (external tools)
Clear-HostClear screen

IntelliJ Variables

VariableDescription
$ProjectFileDir$Project root directory
$FileDir$Directory of currently selected file
$FilePath$Full path of currently selected file
$FileName$Name of currently selected file

Adding Keyboard Shortcuts

  1. Go to File → Settings → Keymap
  2. Search for your external tool name
  3. Right-click and assign shortcut:
    • Ctrl+Alt+P - PowerShell Here
    • Ctrl+Alt+Shift+P - PowerShell Admin Here

Troubleshooting

PowerShell Profile Not Found

# Check if profile exists
Test-Path $PROFILE
 
# Create profile if missing
New-Item -Path $PROFILE -Type File -Force

Chocolatey Not Working

# Verify Chocolatey installation
$env:ChocolateyInstall
 
# Reinstall Chocolatey if needed
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Environment Variables Not Updating

  • Run refreshenv manually in terminal
  • Restart IntelliJ completely
  • Check if PATH cleanup script completed successfully

Benefits

✅ Consistent Environment - Same PowerShell experience as system terminal
✅ Auto-loaded Modules - Chocolatey and custom modules available
✅ Updated PATH - Reflects system changes without IDE restart
✅ Custom Functions - Personal aliases and functions work
✅ Project Context - External tools open in correct directory

Next Steps

  1. Apply terminal settings in IntelliJ
  2. Create external tools for PowerShell access
  3. Test with a simple command like Get-Command refreshenv
  4. Run your PATH cleanup script using the admin tool
  5. Add keyboard shortcuts for quick access