Skip to content

escapePowerShellCommandArg

escapePowerShellCommandArg(expr): string

Defined in: command/escape-powershell-command-arg.ts:20

Escape a string to be safely used as a PowerShell command argument.

It wraps the string in single quotes — inside which PowerShell performs no variable expansion, no subexpression evaluation and no backtick escaping — and doubles any single quote the string already contains, which is the only escape the single-quoted form recognises.

Example:

const unsafe = "It's $(a) `test`";
const safe = escapePowerShellCommandArg(unsafe);
console.log(safe); // 'It''s $(a) `test`'

string

The string to escape

string

The escaped string