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
| Component | Purpose |
|---|---|
pwsh.exe | PowerShell 7+ executable |
-NoExit | Keep terminal open after commands |
-Command | Execute script block |
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 | Load Chocolatey modules |
-ErrorAction SilentlyContinue | Don’t fail if Chocolatey not installed |
if(Test-Path $PROFILE){. $PROFILE} | Load personal PowerShell profile |
refreshenv | Refresh environment variables |
Set-Location '$ProjectFileDir$' | Navigate to project directory (external tools) |
Clear-Host | Clear screen |
IntelliJ Variables
| Variable | Description |
|---|---|
$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
- Go to
File→Settings→Keymap - Search for your external tool name
- Right-click and assign shortcut:
Ctrl+Alt+P- PowerShell HereCtrl+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 -ForceChocolatey 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
refreshenvmanually 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
- Apply terminal settings in IntelliJ
- Create external tools for PowerShell access
- Test with a simple command like
Get-Command refreshenv - Run your PATH cleanup script using the admin tool
- Add keyboard shortcuts for quick access