Execute the passed PowerShell command and return the output as a dictionary. Other ``cmd.*`` functions (besides ``cmd.powershell_all``) return the raw text output of the command. This function appends ``| ConvertTo-JSON`` to the command and then parses the JSON into a Python di
(
cmd,
cwd=None,
stdin=None,
runas=None,
shell="powershell",
env=None,
clean_env=False,
template=None,
rstrip=True,
umask=None,
output_encoding=None,
output_loglevel="debug",
hide_output=False,
timeout=None,
reset_system_locale=True,
ignore_retcode=False,
saltenv=None,
use_vt=False,
password=None,
depth=None,
encode_cmd=False,
success_retcodes=None,
success_stdout=None,
success_stderr=None,
**kwargs,
)
| 4115 | |
| 4116 | |
| 4117 | def powershell( |
| 4118 | cmd, |
| 4119 | cwd=None, |
| 4120 | stdin=None, |
| 4121 | runas=None, |
| 4122 | shell="powershell", |
| 4123 | env=None, |
| 4124 | clean_env=False, |
| 4125 | template=None, |
| 4126 | rstrip=True, |
| 4127 | umask=None, |
| 4128 | output_encoding=None, |
| 4129 | output_loglevel="debug", |
| 4130 | hide_output=False, |
| 4131 | timeout=None, |
| 4132 | reset_system_locale=True, |
| 4133 | ignore_retcode=False, |
| 4134 | saltenv=None, |
| 4135 | use_vt=False, |
| 4136 | password=None, |
| 4137 | depth=None, |
| 4138 | encode_cmd=False, |
| 4139 | success_retcodes=None, |
| 4140 | success_stdout=None, |
| 4141 | success_stderr=None, |
| 4142 | **kwargs, |
| 4143 | ): |
| 4144 | """ |
| 4145 | Execute the passed PowerShell command and return the output as a dictionary. |
| 4146 | |
| 4147 | Other ``cmd.*`` functions (besides ``cmd.powershell_all``) |
| 4148 | return the raw text output of the command. This |
| 4149 | function appends ``| ConvertTo-JSON`` to the command and then parses the |
| 4150 | JSON into a Python dictionary. If you want the raw textual result of your |
| 4151 | PowerShell command you should use ``cmd.run`` with the ``shell=powershell`` |
| 4152 | option. |
| 4153 | |
| 4154 | For example: |
| 4155 | |
| 4156 | .. code-block:: bash |
| 4157 | |
| 4158 | salt '*' cmd.run '$PSVersionTable.CLRVersion' shell=powershell |
| 4159 | salt '*' cmd.run 'Get-NetTCPConnection' shell=powershell |
| 4160 | |
| 4161 | .. versionadded:: 2016.3.0 |
| 4162 | |
| 4163 | .. warning:: |
| 4164 | |
| 4165 | This passes the cmd argument directly to PowerShell |
| 4166 | without any further processing! Be absolutely sure that you |
| 4167 | have properly sanitized the command passed to this function |
| 4168 | and do not use untrusted inputs. |
| 4169 | |
| 4170 | In addition to the normal ``cmd.run`` parameters, this command offers the |
| 4171 | ``depth`` parameter to change the Windows default depth for the |
| 4172 | ``ConvertTo-JSON`` powershell command. The Windows default is 2. If you need |
| 4173 | more depth, set that here. |
| 4174 |
nothing calls this directly
no test coverage detected