Execute the passed PowerShell command and return a dictionary with a result field representing the output of the command, as well as other fields showing us what the PowerShell invocation wrote to ``stderr``, the process id, and the exit code of the invocation. This function ap
(
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",
quiet=False,
timeout=None,
reset_system_locale=True,
ignore_retcode=False,
saltenv=None,
use_vt=False,
password=None,
depth=None,
encode_cmd=False,
force_list=False,
success_retcodes=None,
success_stdout=None,
success_stderr=None,
**kwargs,
)
| 4413 | |
| 4414 | |
| 4415 | def powershell_all( |
| 4416 | cmd, |
| 4417 | cwd=None, |
| 4418 | stdin=None, |
| 4419 | runas=None, |
| 4420 | shell="powershell", |
| 4421 | env=None, |
| 4422 | clean_env=False, |
| 4423 | template=None, |
| 4424 | rstrip=True, |
| 4425 | umask=None, |
| 4426 | output_encoding=None, |
| 4427 | output_loglevel="debug", |
| 4428 | quiet=False, |
| 4429 | timeout=None, |
| 4430 | reset_system_locale=True, |
| 4431 | ignore_retcode=False, |
| 4432 | saltenv=None, |
| 4433 | use_vt=False, |
| 4434 | password=None, |
| 4435 | depth=None, |
| 4436 | encode_cmd=False, |
| 4437 | force_list=False, |
| 4438 | success_retcodes=None, |
| 4439 | success_stdout=None, |
| 4440 | success_stderr=None, |
| 4441 | **kwargs, |
| 4442 | ): |
| 4443 | """ |
| 4444 | Execute the passed PowerShell command and return a dictionary with a result |
| 4445 | field representing the output of the command, as well as other fields |
| 4446 | showing us what the PowerShell invocation wrote to ``stderr``, the process |
| 4447 | id, and the exit code of the invocation. |
| 4448 | |
| 4449 | This function appends ``| ConvertTo-JSON`` to the command before actually |
| 4450 | invoking powershell. |
| 4451 | |
| 4452 | An unquoted empty string is not valid JSON, but it's very normal for the |
| 4453 | Powershell output to be exactly that. Therefore, we do not attempt to parse |
| 4454 | empty Powershell output (which would result in an exception). Instead we |
| 4455 | treat this as a special case and one of two things will happen: |
| 4456 | |
| 4457 | - If the value of the ``force_list`` parameter is ``True``, then the |
| 4458 | ``result`` field of the return dictionary will be an empty list. |
| 4459 | |
| 4460 | - If the value of the ``force_list`` parameter is ``False``, then the |
| 4461 | return dictionary **will not have a result key added to it**. We aren't |
| 4462 | setting ``result`` to ``None`` in this case, because ``None`` is the |
| 4463 | Python representation of "null" in JSON. (We likewise can't use ``False`` |
| 4464 | for the equivalent reason.) |
| 4465 | |
| 4466 | If Powershell's output is not an empty string and Python cannot parse its |
| 4467 | content, then a ``CommandExecutionError`` exception will be raised. |
| 4468 | |
| 4469 | If Powershell's output is not an empty string, Python is able to parse its |
| 4470 | content, and the type of the resulting Python object is other than ``list`` |
| 4471 | then one of two things will happen: |
| 4472 |
nothing calls this directly
no test coverage detected