diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index fe1d4412d00..5ec3a6f6a45 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -293,7 +293,7 @@ def _prep_powershell_cmd(win_shell, cmd, encoded_cmd): # Commands that are a specific keyword behave differently. They fail if # you add a "&" to the front. Add those here as we find them: - keywords = ["$", "&", ".", "Configuration"] + keywords = ["$", "&", ".", "Configuration", "try"] for keyword in keywords: if cmd.startswith(keyword): diff --git a/tests/pytests/unit/modules/test_cmdmod.py b/tests/pytests/unit/modules/test_cmdmod.py index e1f2a604cd1..10d154b98d2 100644 --- a/tests/pytests/unit/modules/test_cmdmod.py +++ b/tests/pytests/unit/modules/test_cmdmod.py @@ -1064,6 +1064,7 @@ def test_prep_powershell_cmd_no_powershell(): [ ("Write-Host foo", "& Write-Host foo"), ("$PSVersionTable", "$PSVersionTable"), + ("try {this} catch {that}", "try {this} catch {that}"), ], ) def test_prep_powershell_cmd(cmd, parsed):