A powerful MCP (Model Context Protocol) server that enables Claude to execute PowerShell commands on Windows systems. Supports both PowerShell 7+ (pwsh.exe) and Windows PowerShell 5.1 (powershell.exe).
- Dual PowerShell Support: Use modern PowerShell 7+ or legacy Windows PowerShell 5.1
- Smart Defaults: Automatically detects and uses PowerShell 7 by default
- Background Processes: Run and manage long-running PowerShell scripts
- Output Management: Automatic truncation and file saving for large outputs
- Script Execution: Run .ps1 script files with arguments
- Version Detection: Check which PowerShell versions are available
- Configurable: Environment variables for customization
cd C:\Users\shaun\repos\mcp-powershell
npm installnpm install -g powershell-mcpAdd to your claude_desktop_config.json:
{
"mcpServers": {
"powershell": {
"command": "node",
"args": ["C:\\Users\\shaun\\repos\\mcp-powershell\\index.js"]
}
}
}{
"mcpServers": {
"powershell": {
"command": "npx",
"args": ["powershell-mcp"]
}
}
}You can customize behavior using environment variables:
{
"mcpServers": {
"powershell": {
"command": "node",
"args": ["C:\\Users\\shaun\\repos\\mcp-powershell\\index.js"],
"env": {
"POWERSHELL_MCP_DEFAULT_SHELL": "pwsh",
"POWERSHELL_MCP_MAX_OUTPUT_SIZE": "102400",
"POWERSHELL_MCP_TEMP_DIR": "C:\\temp\\powershell-mcp",
"POWERSHELL_MCP_PWSH_PATH": "pwsh.exe",
"POWERSHELL_MCP_POWERSHELL_PATH": "powershell.exe"
}
}
}
}| Variable | Default | Description |
|---|---|---|
POWERSHELL_MCP_DEFAULT_SHELL |
pwsh |
Default shell to use: pwsh or powershell |
POWERSHELL_MCP_MAX_OUTPUT_SIZE |
51200 (50KB) |
Max output size before truncation |
POWERSHELL_MCP_TEMP_DIR |
System temp | Directory for storing full outputs |
POWERSHELL_MCP_PWSH_PATH |
pwsh.exe |
Path to PowerShell 7 executable |
POWERSHELL_MCP_POWERSHELL_PATH |
powershell.exe |
Path to Windows PowerShell 5.1 executable |
Execute any PowerShell command with full control over which version to use.
Parameters:
command(string, required): PowerShell command to executecwd(string, optional): Working directorytimeout(number, optional): Timeout in milliseconds (default: 30000)useLegacy(boolean, optional): Use PowerShell 5.1 instead of 7 (default: false)asJson(boolean, optional): Parse output as JSON if possible (default: false)
Examples:
// Simple command (uses PowerShell 7)
run("Get-Process | Select-Object -First 5")
// With working directory
run("Get-ChildItem", { cwd: "C:\\Projects" })
// Use legacy PowerShell 5.1 for compatibility
run("Get-WindowsFeature", { useLegacy: true })
// Parse JSON output
run("Get-Process | Select-Object Name, Id | ConvertTo-Json", { asJson: true })Run a .ps1 script file with arguments.
Parameters:
scriptPath(string, required): Path to .ps1 fileargs(array, optional): Arguments to pass to scriptcwd(string, optional): Working directorytimeout(number, optional): Timeout in milliseconds (default: 30000)useLegacy(boolean, optional): Use PowerShell 5.1 (default: false)
Example:
run_script("C:\\Scripts\\Deploy.ps1", {
args: ["Production", "v1.2.3"],
cwd: "C:\\Projects\\MyApp"
})Get detailed version information for both PowerShell installations.
Example:
get_version()Returns:
{
"success": true,
"available": {
"pwsh": true,
"powershell": true
},
"defaultShell": "pwsh",
"versions": {
"PowerShell 7": {
"PSVersion": "7.5.4",
"PSEdition": "Core"
},
"PowerShell 5.1": {
"PSVersion": "5.1.26100.6899",
"PSEdition": "Desktop"
}
}
}Run a long-running PowerShell command in the background.
Parameters:
command(string, required): PowerShell commandname(string, required): Unique name for the processcwd(string, optional): Working directoryuseLegacy(boolean, optional): Use PowerShell 5.1 (default: false)
Example:
run_background("npm run dev", "frontend-server")Kill a background process by name.
Parameters:
name(string, required): Name of the process to kill
Example:
kill_background("frontend-server")List all running background processes with their status.
Example:
list_background()Advantages:
- Modern features and better performance
- Cross-platform cmdlets
- Regular updates
- Better JSON handling
- Improved error messages
Use when:
- Doing general scripting tasks
- Working with modern APIs
- Need latest PowerShell features
Advantages:
- Comes with Windows
- Some legacy modules only work here
- Certain Windows management tools
Use when:
- Need specific Windows-only modules
- Working with legacy scripts
- Compatibility requirements
Example - Using Legacy Mode:
// Some Windows features require PowerShell 5.1
run("Get-WindowsFeature", { useLegacy: true })When command output exceeds POWERSHELL_MCP_MAX_OUTPUT_SIZE:
- Output is truncated to the specified limit
- Full output is saved to a temporary file
- Response includes the file path for accessing complete output
- Falls back to system temp directory if custom temp dir fails
Example Response with Overflow:
{
"success": true,
"stdout": "...[truncated]...\n\n[Output truncated - exceeded 51200 bytes]\n[Full output saved to: C:\\temp\\powershell-mcp-stdout-2025-10-26.txt]",
"overflow": true,
"details": {
"stdout": {
"originalSize": 150000,
"truncatedSize": 51200,
"filePath": "C:\\temp\\powershell-mcp-stdout-2025-10-26.txt"
}
}
}All tools return JSON responses:
{
"success": true,
"stdout": "command output",
"stderr": "error output if any",
"command": "executed command",
"shell": "PowerShell 7"
}Get-Process | Sort-Object CPU -Descending | Select-Object -First 10# List all services
Get-Service
# Start a service (requires admin)
Start-Service -Name "wuauserv"# Get files modified in last 24 hours
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) }# Get network adapters
Get-NetAdapter | Select-Object Name, Status, LinkSpeed
# Test connectivity
Test-NetConnection -ComputerName google.com -Port 443This MCP server executes arbitrary PowerShell commands with the same privileges as the Node.js process.
Best Practices:
- Only use in development environments or trusted contexts
- Run with least privilege necessary
- Review commands before execution when possible
- Use appropriate execution policies
- Monitor background processes
- Node.js >= 16.0.0
- Windows 10/11 or Windows Server
- PowerShell 7+ (recommended) or Windows PowerShell 5.1
If you get errors about pwsh.exe not being found:
- Install PowerShell 7 from Microsoft Store or https://github.com/PowerShell/PowerShell
- Or configure to use Windows PowerShell 5.1 by default:
{
"env": {
"POWERSHELL_MCP_DEFAULT_SHELL": "powershell"
}
}If you see execution policy errors:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserSome commands require administrator privileges. Run Claude Desktop as administrator if needed.
# Clone repository
git clone https://github.com/YourUsername/mcp-powershell.git
cd mcp-powershell
# Install dependencies
npm install
# Run locally
node index.jsMIT
Shaun Prince
Issues and pull requests are welcome at GitHub.
Inspired by bash-mcp by tinywind.