From 987d1b6aedba62d9f9a2ba5f982310399eb3a437 Mon Sep 17 00:00:00 2001
From: Dafydd Jones <dafydd@techneg.it>
Date: Fri, 10 Mar 2023 19:04:47 +0000
Subject: [PATCH 1/3] test: debug logging for `win_pkg.remove`

---
 tests/pytests/unit/modules/test_win_pkg.py | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/tests/pytests/unit/modules/test_win_pkg.py b/tests/pytests/unit/modules/test_win_pkg.py
index 168c24aff146..d8551f9a85a5 100644
--- a/tests/pytests/unit/modules/test_win_pkg.py
+++ b/tests/pytests/unit/modules/test_win_pkg.py
@@ -501,6 +501,51 @@ def test_pkg_install_minion_error_salt_cache_dir():
         assert ret == expected
 
 
+def test_pkg_remove_log_message(caplog):
+    """
+    test pkg.remove pkg logging
+    """
+    ret__get_package_info = {
+        "3.03": {
+            "uninstaller": "%program.exe",
+            "reboot": False,
+            "msiexec": False,
+            "installer": "runme.exe",
+            "uninstall_flags": "/S",
+            "locale": "en_US",
+            "install_flags": "/s",
+            "full_name": "Firebox 3.03 (x86 en-US)",
+        }
+    }
+
+    mock_cmd_run_all = MagicMock(return_value={"retcode": 0})
+    se_list_pkgs = {"firebox": ["3.03"]}
+    with patch.object(win_pkg, "list_pkgs", return_value=se_list_pkgs), patch.object(
+        salt.utils.data, "is_true", MagicMock(return_value=True)
+    ), patch.object(
+        win_pkg, "_get_package_info", MagicMock(return_value=ret__get_package_info)
+    ), patch.dict(
+        win_pkg.__salt__,
+        {
+            "pkg_resource.parse_targets": MagicMock(
+                return_value=[{"firebox": "3.03"}, None]
+            ),
+            "cp.is_cached": MagicMock(return_value="C:\\fake\\path.exe"),
+            "cmd.run_all": mock_cmd_run_all,
+        },
+    ), caplog.at_level(
+        logging.DEBUG
+    ):
+        win_pkg.remove(
+            pkgs=["firebox"],
+        )
+        assert (
+            'PKG : cmd: C:\\WINDOWS\\system32\\cmd.exe /s /c "%program.exe" /S'
+        ).lower() in [x.lower() for x in caplog.messages]
+        assert "PKG : pwd: ".lower() in [x.lower() for x in caplog.messages]
+        assert "PKG : retcode: 0" in caplog.messages
+
+
 def test_pkg_remove_minion_error_salt_cache_dir():
     """
     Test pkg.remove when cp.cache_dir encounters a minion error

From d9e95be7bcdd4c59d0c4ac5897c5f5cf455c48d2 Mon Sep 17 00:00:00 2001
From: Dafydd Jones <dafydd@techneg.it>
Date: Fri, 10 Mar 2023 19:35:12 +0000
Subject: [PATCH 2/3] feat(win_pkg): add debug logging for `win_pkg.remove`

---
 salt/modules/win_pkg.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/salt/modules/win_pkg.py b/salt/modules/win_pkg.py
index 46202fcad3d7..4aa73422f44e 100644
--- a/salt/modules/win_pkg.py
+++ b/salt/modules/win_pkg.py
@@ -2154,6 +2154,8 @@ def remove(name=None, pkgs=None, **kwargs):
             # Uninstall the software
             changed.append(pkgname)
             # Check Use Scheduler Option
+            log.debug("PKG : cmd: %s /s /c %s", cmd_shell, arguments)
+            log.debug("PKG : pwd: %s", cache_path)
             if pkginfo[target].get("use_scheduler", False):
                 # Create Scheduled Task
                 __salt__["task.create_task"](
@@ -2184,6 +2186,7 @@ def remove(name=None, pkgs=None, **kwargs):
                     python_shell=False,
                     redirect_stderr=True,
                 )
+                log.debug("PKG : retcode: %s", result["retcode"])
                 if not result["retcode"]:
                     ret[pkgname] = {"uninstall status": "success"}
                     changed.append(pkgname)

From b25f5ffc839b325f6b73060c289ba6f9593c55a2 Mon Sep 17 00:00:00 2001
From: Dafydd Jones <dafydd@techneg.it>
Date: Sun, 12 Mar 2023 16:35:19 +0000
Subject: [PATCH 3/3] add changelog

---
 changelog/63866.added.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 changelog/63866.added.md

diff --git a/changelog/63866.added.md b/changelog/63866.added.md
new file mode 100644
index 000000000000..4aa7872dedc4
--- /dev/null
+++ b/changelog/63866.added.md
@@ -0,0 +1 @@
+Added debug log messages displaying the command being run when removing packages on Windows