mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-20 15:01:40 -04:00
Updated winrm and winrmcp dependencies. Relevant unit and acceptance tests passed successfully. shell.Execute didn't return a Command object. See https://github.com/packer-community/winrmcp/blob/f1bcf36a69fa2945e65dd099eee11b560fbd3346/winrmcp/cp.go#L167 and https://github.com/masterzen/winrm/blob/54ea5d01478cfc2afccec1504bd0dfcd8c260cfa/winrm/shell.go#L10-L22 respectively. Closes #3763 Original patch by: Philipp Kosel <[email protected]>
24 lines
563 B
Go
24 lines
563 B
Go
package winrm
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
)
|
|
|
|
// Powershell wraps a PowerShell script
|
|
// and prepares it for execution by the winrm client
|
|
func Powershell(psCmd string) string {
|
|
// 2 byte chars to make PowerShell happy
|
|
wideCmd := ""
|
|
for _, b := range []byte(psCmd) {
|
|
wideCmd += string(b) + "\x00"
|
|
}
|
|
|
|
// Base64 encode the command
|
|
input := []uint8(wideCmd)
|
|
encodedCmd := base64.StdEncoding.EncodeToString(input)
|
|
|
|
// Create the powershell.exe command line to execute the script
|
|
return fmt.Sprintf("powershell.exe -EncodedCommand %s", encodedCmd)
|
|
}
|