win_shell cmd parsing domain\usernmame issue

Hello,

I am trying to use the win_shell module to run a script which includes the username parameter.

  • name: Execute {{ set_wmi}} to capture the existing user accounts for WMI security for the root namespace
    win_shell: .\set-WmiNamespaceSecurity.ps1 root add “domain\username_sls” Enable,RemoteAccess,Methodexecute
    args:
    chdir: “{{ temp }}”
    register: set_wminamespace

The result always seems to be “account not found”. I am not sure if it is trying to always pass the \ as part of the username.

If anyone can help or advise here, that would be much appreciated as I think I have tried username@domain, also I have tried to use variables instead of the actual account. Tried single and double quotes, everything results in account not found.

TASK [Execute Set-WmiNamespaceSecurity.ps1 to capture the existing user accounts for WMI security for the root namespace] ***
Wednesday 10 May 2023 06:06:09 +0000 (0:00:00.062) 0:00:46.653 *********
fatal: [xxyzwappf0013.domain]: FAILED! => {“changed”: true, “cmd”: “.\\set-WmiNamespaceSecurity.ps1 root add \“domain\\username_sls\” Enable,RemoteAccess,Methodexecute”, “delta”: “0:00:01.203183”, “end”: “2023-05-10 06:06:13.528524”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2023-05-10 06:06:12.325341”, “stderr”: “Account was not found: domain\\username_sls\r\nAt C:\\temp\\wmi\\Set-WmiNamespaceSecurity.ps1:138 char:9\r\n+ throw \“Account was not found: $account\”\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : OperationStopped: (Account was not…username \r\n _sls:String) , RuntimeException\r\n + FullyQualifiedErrorId : Account was not found: domain\\username_sls”, “stderr_lines”: [“Account was not found: domain\\username_sls”, “At C:\\temp\\wmi\\Set-WmiNamespaceSecurity.ps1:138 char:9”, “+ throw \“Account was not found: $account\””, “+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”, " + CategoryInfo : OperationStopped: (Account was not…username “, " _sls:String) , RuntimeException”, " + FullyQualifiedErrorId : Account was not found: domain\\username_sls"], “stdout”: “”, “stdout_lines”: }
…ignoring

I have never done WMI through Ansible. My role does not require it of me. That said, it looks like you are running a script already installed on the target box. If that’s correct, can you output the exact value of the $account variable? I believe that would tell you what your input variable needs to look like.

Kevin