From 68d18b2ad3bb962ac2a30e9101e9253699db8819 Mon Sep 17 00:00:00 2001 From: Shane Lee Date: Mon, 22 Jul 2024 08:32:24 -0600 Subject: [PATCH] Fix win_dsc tests --- salt/modules/cmdmod.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index c76357ee1ac..1891c044fb0 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -291,8 +291,14 @@ def _prep_powershell_cmd(win_shell, cmd, encoded_cmd): if isinstance(cmd, list): cmd = " ".join(cmd) - if cmd.startswith("$"): - new_cmd.extend(["-Command", f"{cmd.strip()}"]) + # 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"] + + for keyword in keywords: + if cmd.startswith(keyword): + new_cmd.extend(["-Command", f"{cmd.strip()}"]) + break else: new_cmd.extend(["-Command", f"& {cmd.strip()}"])