mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Try setting PSModulePath in cmd.script
This commit is contained in:
parent
a633493f4c
commit
f22c6cabc0
2 changed files with 18 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue