[BUG] cmd.run onlyif powershell
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
Can't get cmd.run working with onlyif and powershell.
As you can see in the screenshot, the exact same command is executed and returns a False, so it shouldn't have been executed in the first place.
I tried also with " instead of ' and completely without and adding powershell infront. But either it's always True or always False independent of the real status.
And it's also really hard to find examples for Windows at all.
Expected behavior
command should only be executed if onlyif is true.
Screenshots

Versions Report
Salt Version:
Salt: 3005.1
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.10 (default, Nov 14 2022, 12:59:47)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 20.0.0
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2
System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-144-generic
system: Linux
version: Ubuntu 20.04 focal
DisableDefenderRTP:
cmd.run:
- name: '(Get-MpComputerStatus).RealTimeProtectionEnabled'
- shell: powershell
- onlyif: '(Get-MpComputerStatus).RealTimeProtectionEnabled'
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Salt's cmd.run entry point and the onlyif handling for the powershell shell, using the provided YAML example and Salt 3005.1 environment to reproduce the behavior. Trace how the condition is evaluated versus the command and verify that the command runs only when the PowerShell condition returns true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, python
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100