hyperv_exec
Runs PowerShell commands as administrator inside a running Hyper-V guest via PowerShell Direct, returning the guest output and exit code; requires a booted Windows guest with integration services.
Instructions
Run a PowerShell command inside a Hyper-V guest as its administrator, over PowerShell Direct. Returns the guest output verbatim plus the guest exit code. Requires a stored credential (hyperv_credential_set). REQUIRES A LIVE GUEST OPERATING SYSTEM — a powered-on VM is not enough: PowerShell Direct has no channel into a guest that has not booted a Windows OS with the Hyper-V integration services running. If the VM is off it is started automatically and waited for, and then the guest heartbeat is waited on; when no guest ever answers, the tool reports GUEST_UNAVAILABLE and KEEPS the stored credential, because that failure is not a password problem. Use hyperv_vm_list to see each VM's heartbeat, and hyperv_host_exec for host-side work that needs no guest at all. The working directory defaults to whatever the remote session inherits, which is stable but not obvious; set workingDirectory when the script uses relative paths, and the resolved directory is reported back with the output. timeoutMs bounds only the host-side wait: a command already running inside the guest keeps running after this call times out, because the guest is a separate machine. hyperv_host_exec behaves differently — it owns a timer inside the elevated process and does stop its script. It is a Session 0 background session: commands run, but GUI windows it opens are not visible to the user.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"vm": "<vm>",
"command": "<command>"
},
"name": "hyperv_exec"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vm | Yes | Name of the Hyper-V virtual machine, as shown by hyperv_vm_list. | |
| command | Yes | PowerShell source to run inside the guest. May be multi-line. Runs as the guest administrator. | |
| timeoutMs | No | Host-side wait limit in milliseconds. Default 60000. | |
| workingDirectory | No | Directory the guest script starts in. Defaults to the directory the remote session inherits. Set it explicitly when the script uses relative paths. |