Skip to content

Commit

Permalink
Issue #752 Fall back to standard location of posh if not found in PATH
Browse files Browse the repository at this point in the history
if exec.LookPath can't find the location of powershell.exe
we fall back to using C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • Loading branch information
anjannath authored and praveenkumar committed Nov 1, 2019
1 parent 918a7e1 commit 17fbfa6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/os/windows/powershell/powershell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ var (
"$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())",
"$currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)",
}

poshStdLocation = filepath.Join(os.Getenv("SYSTEMROOT"), "System32", "WindowsPowerShell", "v1.0", "powershell.exe")
)

func LocatePowerShell() string {
ps, _ := exec.LookPath("powershell.exe")
ps, err := exec.LookPath("powershell.exe")
if err != nil {
logging.Debugf("Could not find powershell.exe on path %s", err.Error())
logging.Debug("Falling back to ", poshStdLocation)
return poshStdLocation
}
return ps
}

Expand Down

0 comments on commit 17fbfa6

Please sign in to comment.