PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/ |
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 IP: 209.182.202.254 |
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_pwsh.py |
import salt.modules.cmdmod import salt.utils.json import salt.utils.platform from salt.exceptions import CommandExecutionError def run_dict(cmd, cwd=None): """ Execute the powershell command and return the data as a dictionary .. versionadded:: 3006.9 Args: cmd (str,list): The powershell command to run cwd (str): The current working directory Returns: dict: A dictionary containing the output of the powershell command Raises: CommandExecutionError: If an error is encountered or the command does not complete successfully """ if isinstance(cmd, list): cmd = " ".join(map(str, cmd)) if "convertto-json" not in cmd.lower(): cmd = f"{cmd} | ConvertTo-Json" if "progresspreference" not in cmd.lower(): cmd = f"$ProgressPreference = 'SilentlyContinue'; {cmd}" ret = salt.modules.cmdmod.run_all(cmd=cmd, shell="powershell", cwd=cwd) if "pid" in ret: del ret["pid"] if ret.get("stderr", ""): error = ret["stderr"].splitlines()[0] raise CommandExecutionError(error, info=ret) if "retcode" not in ret or ret["retcode"] != 0: # run_all logs an error to log.error, fail hard back to the user raise CommandExecutionError("Issue executing PowerShell cmd", info=ret) # Sometimes Powershell returns an empty string, which isn't valid JSON if ret["stdout"] == "": ret["stdout"] = "{}" try: ret = salt.utils.json.loads(ret["stdout"], strict=False) except ValueError: raise CommandExecutionError("No JSON results from PowerShell", info=ret) return ret