powershell

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package powershell provides helpers for powershell command generation

Index

Constants

View Source
const PipeHasEnded = "The pipe has been ended."

PipeHasEnded string is used during the base64+sha265 upload process.

View Source
const PipeIsBeingClosed = "The pipe is being closed."

PipeIsBeingClosed string is used during the base64+sha265 upload process.

Variables

This section is empty.

Functions

func Cmd

func Cmd(psCmd string) string

Cmd builds a command-line for executing a PowerShell command or script. The command is always passed via -EncodedCommand (base64 UTF-16LE): the payload is opaque to both cmd.exe and PowerShell, so it survives intact regardless of the outer login shell. This matters when the remote host runs OpenSSH with DefaultShell=PowerShell, where a plain -Command "..." argument would be parsed and its $-tokens expanded by the outer shell before the inner powershell.exe ever sees them. The trade-off is unreadable command lines, but the runner's debug log decodes -EncodedCommand back to the original script.

func CompressedCmd

func CompressedCmd(psCmd string) string

CompressedCmd creates a scriptlet that will decompress and execute a gzipped script to both avoid command line length limits and to reduce data transferred.

func DoubleQuote

func DoubleQuote(str string) string

DoubleQuote adds double quotes around a string and escapes any double quotes inside.

func DoubleQuotePath

func DoubleQuotePath(v string) string

DoubleQuotePath adds double quotes around a string and escapes any double quotes inside. It also converts forward slashes to backslashes.

func EncodeCmd

func EncodeCmd(psCmd string) string

EncodeCmd base64-encodes a string as UTF-16LE in a way that is accepted by PowerShell -EncodedCommand.

func SingleQuote

func SingleQuote(str string) string

SingleQuote quotes and escapes a string in a format that is accepted by powershell scriptlets from jbrekelmans/go-winrm/util.go PowerShellSingleQuotedStringLiteral.

func SingleQuotePath

func SingleQuotePath(v string) string

SingleQuotePath single-quotes a path and converts forward slashes to backslashes. Use this instead of DoubleQuotePath when the value is passed to a -LiteralPath parameter or any context where PowerShell variable interpolation (e.g. '$' in directory names like C:\$Recycle.Bin) must not occur.

func ToWindowsPath

func ToWindowsPath(v string) string

ToWindowsPath converts a unix-style forward slash separated path to a windows-style path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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