run_powershell
Execute PowerShell commands and scripts to automate Windows system tasks through the Windows Automation MCP Server.
Instructions
执行 PowerShell 命令或脚本
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | PowerShell 命令或脚本 | |
| timeout | No | 超时时间(毫秒,可选) |
Implementation Reference
- src/tools/powershell.js:86-105 (handler)The core handler function implementing the execution of PowerShell commands with error handling, timeout support, and structured response.async runPowerShell(command, timeout = 30000) { try { const { stdout, stderr } = await execAsync( `powershell -Command "${command.replace(/"/g, '\\"')}"`, { shell: 'powershell.exe', timeout, maxBuffer: 1024 * 1024 * 10, // 10MB } ); return { success: true, output: stdout.trim(), error: stderr.trim(), command }; } catch (error) { return { success: false, error: error.message, command }; } }
- src/tools/powershell.js:15-22 (schema)Input schema defining required 'command' parameter and optional 'timeout' for the run_powershell tool.inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'PowerShell 命令或脚本' }, timeout: { type: 'number', description: '超时时间(毫秒,可选)' }, }, required: ['command'], },
- src/tools/powershell.js:12-23 (registration)Tool definition object registering the 'run_powershell' tool with name, description, and schema in getToolDefinitions().{ name: 'run_powershell', description: '执行 PowerShell 命令或脚本', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'PowerShell 命令或脚本' }, timeout: { type: 'number', description: '超时时间(毫秒,可选)' }, }, required: ['command'], }, },
- src/tools/powershell.js:71-72 (registration)Registration and dispatch logic in executeTool switch statement, mapping tool name to handler.case 'run_powershell': return await this.runPowerShell(args.command, args.timeout);
- src/tools/powershell.js:64-65 (helper)Helper list used in canHandle() to check if the tool can be handled.const tools = ['run_powershell', 'run_cmd', 'get_system_info', 'get_disk_info', 'get_network_info'];