execute_ps
Execute PowerShell commands directly on Windows systems. Use the tool to run scripts, manage modules, and retrieve system information efficiently via the PowerShell MCP Server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | PowerShell command to execute |
Implementation Reference
- src/index.ts:39-76 (handler)Handler function that executes the provided PowerShell command using Node.js child_process execAsync. Escapes double quotes in the command, captures stdout and stderr, and returns formatted text content or error response.async ({ command }: { command: string }) => { try { const { stdout, stderr } = await execAsync( `powershell -Command "${command.replace(/"/g, '\\"')}"` ); if (stderr) { return { isError: true, content: [ { type: 'text' as const, text: `Error executing PowerShell command: ${stderr}`, }, ], }; } return { content: [ { type: 'text' as const, text: stdout, }, ], }; } catch (error) { return { isError: true, content: [ { type: 'text' as const, text: `Error executing PowerShell command: ${(error as Error).message}`, }, ], }; } }
- src/index.ts:36-38 (schema)Zod schema defining the input parameter 'command' as a string for the execute_ps tool.{ command: z.string().describe('PowerShell command to execute'), },
- src/index.ts:34-77 (registration)Registration of the 'execute_ps' tool with the MCP server using this.server.tool, including inline schema and handler.this.server.tool( 'execute_ps', { command: z.string().describe('PowerShell command to execute'), }, async ({ command }: { command: string }) => { try { const { stdout, stderr } = await execAsync( `powershell -Command "${command.replace(/"/g, '\\"')}"` ); if (stderr) { return { isError: true, content: [ { type: 'text' as const, text: `Error executing PowerShell command: ${stderr}`, }, ], }; } return { content: [ { type: 'text' as const, text: stdout, }, ], }; } catch (error) { return { isError: true, content: [ { type: 'text' as const, text: `Error executing PowerShell command: ${(error as Error).message}`, }, ], }; } } );