Documentation
¶
Overview ¶
Package psdirect implements vmsdk.GuestExec via PowerShell Direct using the go-psrp library's native PSRP/HvSocket transport. No powershell.exe subprocess is needed — PSRP is spoken in Go directly.
Index ¶
- type Exec
- func (e *Exec) Exec(ctx context.Context, cmd string, args ...string) (*vmsdk.ExecResult, error)
- func (e *Exec) ExecStream(ctx context.Context, cmd string, args []string, sink eventstream.Sink) (*vmsdk.ExecResult, error)
- func (e *Exec) ExecStreamText(ctx context.Context, text string, sink eventstream.Sink) (*vmsdk.ExecResult, error)
- func (e *Exec) ExecText(ctx context.Context, text string) (*vmsdk.ExecResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Exec ¶
type Exec struct {
// VMID is the Hyper-V VM GUID (the resource ID from the hyperv driver).
VMID string
// Username and Password are the guest OS credentials for PSRP authentication.
Username string
Password string
// Domain is the guest domain for authentication ("." for local accounts).
// Defaults to "." if empty.
Domain string
// contains filtered or unexported fields
}
Exec implements vmsdk.GuestExec via PowerShell Direct (HvSocket/PSRP). It communicates with the VM guest using the PSRP wire protocol natively — no powershell.exe subprocess is required.
The guest must have PowerShell remoting enabled (enabled by default on Windows Server; run Enable-PSRemoting on Windows 10/11).
func (*Exec) Exec ¶
Exec runs cmd with args on the Windows guest via PowerShell Direct (HvSocket). Stdout is captured via Out-String; $LASTEXITCODE is returned as the exit code.
func (*Exec) ExecStream ¶ added in v0.1.34
func (e *Exec) ExecStream(ctx context.Context, cmd string, args []string, sink eventstream.Sink) (*vmsdk.ExecResult, error)
func (*Exec) ExecStreamText ¶ added in v0.1.60
func (e *Exec) ExecStreamText(ctx context.Context, text string, sink eventstream.Sink) (*vmsdk.ExecResult, error)
ExecStreamText streams opaque PowerShell text without converting it to argv.
func (*Exec) ExecText ¶ added in v0.1.60
ExecStream runs cmd through PowerShell Direct and forwards PSRP output as it arrives. PowerShell's merged native output is represented on stdout; PSRP error, warning, verbose, debug, progress, and information records are all merged onto stderr — none of those are exclusively "errors", so a caller deciding whether a command failed should rely on the exit code, not on whether anything arrived on the stderr channel. ExecText executes opaque PowerShell text without converting it to argv.