Skip to content

Commit 5ff9c5e

Browse files
committed
windows: set text encodig for powershell to utf-8
by default powershell uses the OEM-US/codepage 437 encoding which is an extension of ASCII when a character with umlaut is used and powershell uses the default encoding go is unable to properly convert it to a go string as it doesn't understand the OEM-US encoding by default and replaces it with 'U+FFFD' and we get a ? in the output the preflight check, checking if username in group fails since the username is not correct because of the '?' character in it, this fixes it by using the utf-8 encoding for powershell
1 parent d40cdbd commit 5ff9c5e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/os/windows/powershell/powershell_windows.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ func Execute(args ...string) (string, string, error) {
3636
if err != nil {
3737
return "", "", err
3838
}
39-
args = append([]string{"-NoProfile", "-NonInteractive", "-ExecutionPolicy", "RemoteSigned", "-Command", "$ProgressPreference = 'SilentlyContinue';"}, args...)
39+
args = append([]string{"-NoProfile", "-NonInteractive", "-ExecutionPolicy", "RemoteSigned", "-Command",
40+
"$ProgressPreference = 'SilentlyContinue';", "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new();"}, args...)
4041
cmd := exec.Command(powershell, args...) // #nosec G204
4142
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
4243

@@ -85,6 +86,7 @@ func ExecuteAsAdmin(reason, cmd string) (string, string, error) {
8586

8687
func runAsCmds(powershell string) []string {
8788
return []string{
89+
`[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new();`,
8890
`$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();`,
8991
`$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);`,
9092
`$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;`,

0 commit comments

Comments
 (0)