2016-02-22 14:44:12 -05:00
|
|
|
package winrm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2016-10-01 16:34:42 -04:00
|
|
|
// Powershell wraps a PowerShell script
|
|
|
|
// and prepares it for execution by the winrm client
|
2016-02-22 14:44:12 -05:00
|
|
|
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)
|
|
|
|
}
|