diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index f136bdf1c..47ce809ac 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -33,7 +33,7 @@ func LookPath(name string) (string, error) { exts = append(exts, e) } } else { - exts = []string{".com", ".exe", ".bat", ".cmd"} + exts = []string{".com", ".exe", ".bat", ".cmd", ".ps1"} } for _, ext := range exts { path := filepath.Join(step.BasePath(), "plugins", fileName+ext) @@ -54,8 +54,16 @@ func LookPath(name string) (string, error) { // it to complete. func Run(ctx *cli.Context, file string) error { args := ctx.Args() - //nolint:gosec // arguments controlled by step. - cmd := exec.Command(file, args[1:]...) + cmdName := file + + // if running on Windows and (likely) a PowerShell script, invoke powershell + // with the arguments instead of the plugin file directly. + if runtime.GOOS == "windows" && filepath.Ext(file) == ".ps1" { + cmdName = "powershell" + args = append([]string{args[0], "-noprofile", "-nologo", file}, args[1:]...) + } + + cmd := exec.Command(cmdName, args[1:]...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr