Skip to main content
Glama

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

NameRequiredDescriptionDefault
commandYesPowerShell command to execute

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "command": { "description": "PowerShell command to execute", "type": "string" } }, "required": [ "command" ], "type": "object" }

Implementation Reference

  • 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}`, }, ], }; } }
  • 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}`, }, ], }; } } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/posidron/mcp-powershell'

If you have feedback or need assistance with the MCP directory API, please join our Discord server