Try setting PSModulePath in cmd.script

This commit is contained in:
twangboy 2025-01-14 15:06:58 -07:00 committed by Daniel Wozniak
parent a633493f4c
commit f22c6cabc0
2 changed files with 18 additions and 7 deletions

View file

@ -2942,6 +2942,23 @@ def script(
else:
cmd_path = _cmd_quote(path)
if not env:
env = {}
paths = [
fr'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules',
fr'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules',
fr'{os.getenv("ProgramFiles(x86)", "")}\WindowsPowerShell\Modules',
]
ps_module_path = os.getenv("PSModulePath", "").split(";")
for path in paths:
if os.path.exists(path):
ps_module_path.append(path)
env.update({"PSModulePath": ";".join(ps_module_path)})
ret = _run(
cmd_path + " " + str(args) if args else cmd_path,
cwd=cwd,

View file

@ -57,13 +57,7 @@ def test_windows_script_args_powershell(cmd, shell, issue_56195):
)
script = "salt://issue-56195/test.ps1"
ret = cmd.script(
source=script,
args=args,
shell="powershell",
saltenv="base",
env={"PSModulePath": ""},
)
ret = cmd.script(source=script, args=args, shell="powershell", saltenv="base")
assert ret["stdout"] == password