From d721b67cc6d9c183f9270241c0f0ba733f02a29e Mon Sep 17 00:00:00 2001 From: lkwiatek <139439600+lkwiatek@users.noreply.github.com> Date: Thu, 13 Jul 2023 08:01:43 +0000 Subject: [PATCH] Use "powershell.exe" instead of just "powershell" for .ps1 script execution. This change significantly reduce the number of paths the OS looks for the powershell command. --- goolib/goolib.go | 4 ++-- goolib/goolib_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/goolib/goolib.go b/goolib/goolib.go index e345bb4..00ef140 100644 --- a/goolib/goolib.go +++ b/goolib/goolib.go @@ -30,7 +30,7 @@ import ( ) var interpreter = map[string]string{ - ".ps1": "powershell", + ".ps1": "powershell.exe", ".cmd": "cmd", ".bat": "cmd", ".exe": "cmd", @@ -59,7 +59,7 @@ func Exec(s string, args []string, ec []int, w io.Writer) error { return err } switch ipr { - case "powershell": + case "powershell.exe": // We are using `-Command` here instead of `-File` as this catches syntax errors in the script. args = append([]string{"-ExecutionPolicy", "Bypass", "-NonInteractive", "-NoProfile", "-Command", cs}, args...) c = exec.Command(ipr, args...) diff --git a/goolib/goolib_test.go b/goolib/goolib_test.go index 76e9716..bc6ba25 100644 --- a/goolib/goolib_test.go +++ b/goolib/goolib_test.go @@ -26,7 +26,7 @@ func TestScriptInterpreter(t *testing.T) { script string eitp string }{ - {"/file/path/script.ps1", "powershell"}, + {"/file/path/script.ps1", "powershell.exe"}, {"/file/path/script.cmd", "cmd"}, {"/file/path/script.bat", "cmd"}, }