winrmclient

package
v0.0.0-...-484183c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package winrmclient provides a thin WinRM wrapper for executing PowerShell commands on remote Windows hosts via WinRM (PowerShell Remoting).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discover

func Discover(ctx context.Context, cfg DiscoverConfig, log *slog.Logger) (*Client, Config, error)

Discover tries multiple WinRM transport configurations and returns the first working client. It probes in order: HTTP+NTLM:5985, HTTPS+NTLM:5986, HTTP+Basic:5985, HTTPS+Basic:5986. Each probe runs a lightweight PowerShell command with a short timeout. The returned client uses the full operational timeout from cfg.Timeout.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps a WinRM connection to a remote Windows host.

func New

func New(cfg Config) (*Client, error)

New creates a WinRM client. The connection is established lazily on first command.

func (*Client) RunPowerShell

func (c *Client) RunPowerShell(ctx context.Context, script string) (string, string, error)

RunPowerShell executes a PowerShell script on the remote host. Returns stdout, stderr, and any error (including non-zero exit codes).

type Config

type Config struct {
	Host     string
	Port     int
	Username string // DOMAIN\user or user@domain
	Password string
	UseHTTPS bool
	UseBasic bool // Use Basic auth instead of NTLM
	Timeout  time.Duration
}

Config holds WinRM connection parameters.

type DiscoverConfig

type DiscoverConfig struct {
	Host     string
	Username string
	Password string
	Timeout  time.Duration // operational timeout for the returned client
}

DiscoverConfig holds non-transport WinRM parameters for auto-discovery. Discover() cycles through transport combinations to find a working one.

type Executor

type Executor interface {
	RunPowerShell(ctx context.Context, script string) (stdout, stderr string, err error)
}

Executor is the interface consumed by epamatrix for executing remote PowerShell.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL