// Package winexec runs PowerShell on Windows hosts. // // It exists because three subsystems - updates, workload collection and // workload logs - all need the same invocation, and because getting a // multi-line script past Go quoting, cmd.exe quoting and PowerShell's own // parser is a problem worth solving once. package winexec import ( "encoding/base64" "unicode/utf16" ) // EncodeCommand renders a script for powershell.exe -EncodedCommand: UTF-16LE, // no byte-order mark, base64. This is deliberately free of build tags so it is // tested on a Linux development machine like every other pure function here. func EncodeCommand(script string) string { units := utf16.Encode([]rune(script)) b := make([]byte, 0, len(units)*2) for _, u := range units { b = append(b, byte(u), byte(u>>8)) } return base64.StdEncoding.EncodeToString(b) }