run_powershell
Execute PowerShell commands and scripts to automate Windows system administration tasks, manage processes, and control system operations through the Windows Automation MCP Server.
Instructions
执行 PowerShell 命令或脚本
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | PowerShell 命令或脚本 | |
| timeout | No | 超时时间(毫秒,可选) |
Input Schema (JSON Schema)
{
"properties": {
"command": {
"description": "PowerShell 命令或脚本",
"type": "string"
},
"timeout": {
"description": "超时时间(毫秒,可选)",
"type": "number"
}
},
"required": [
"command"
],
"type": "object"
}
Implementation Reference
- src/tools/powershell.js:12-23 (registration)Registration of the 'run_powershell' tool including name, description, and input schema in the getToolDefinitions method.{ name: 'run_powershell', description: '执行 PowerShell 命令或脚本', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'PowerShell 命令或脚本' }, timeout: { type: 'number', description: '超时时间(毫秒,可选)' }, }, required: ['command'], }, },
- src/tools/powershell.js:86-105 (handler)The core handler function that executes the PowerShell command using child_process.execAsync, handles timeout, captures output and errors.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:71-72 (handler)Dispatch logic in the executeTool method that routes 'run_powershell' calls to the runPowerShell handler.case 'run_powershell': return await this.runPowerShell(args.command, args.timeout);