0

Ansible win_shell/win_command prints logo output instead of actual output of the command:

- name: get Ps1 files
      win_shell: get-ChildItem -path $testFolder -Filter *.ps1 -Recurse -File -Name -Depth 0
      register: ps1_files
      args:
        executable: powershell

Should print a list of *.ps1 folders but instead prints wrong output (command works when running directly on powershell on the server):

"msg": {
2022-12-22T02:30:46.455812-0500 info:         "changed": true, 
2022-12-22T02:30:46.455867-0500 info:         "cmd": "get-ChildItem -path $realProcessesFolder -Filter *.ps1 -Recurse -File -Name -Depth 0", 
2022-12-22T02:30:46.455917-0500 info:         "delta": "0:00:00.954839", 
2022-12-22T02:30:46.455969-0500 info:         "end": "2022-12-22 07:30:46.385668", 
2022-12-22T02:30:46.456017-0500 info:         "failed": false, 
2022-12-22T02:30:46.456065-0500 info:         "rc": 0, 
2022-12-22T02:30:46.456115-0500 info:         "start": "2022-12-22 07:30:45.430828", 
2022-12-22T02:30:46.456165-0500 info:         "stderr": "", 
2022-12-22T02:30:46.456237-0500 info:         "stderr_lines": [], 
2022-12-22T02:30:46.456289-0500 info:         "stdout": "\r\n\r\nComputerName  : SL143312\r\nBuilddate     : 2019-Aug-26 13:43:8\r\nProfile       : Standard Application Server\r\nOS            : Windows Server 2016 Standard Edition\r\nMachineType   : VMware Virtual Platform\r\nModel         : VMware, Inc.\r\nServerAppCode : TVP0\r\n\r\n\r\n\r\n", 
2022-12-22T02:30:46.456343-0500 info:         "stdout_lines": [
2022-12-22T02:30:46.456393-0500 info:             "", 
2022-12-22T02:30:46.456445-0500 info:             "", 
2022-12-22T02:30:46.456504-0500 info:             "ComputerName  : SL143312", 
2022-12-22T02:30:46.456556-0500 info:             "Builddate     : 2019-Aug-26 13:43:8", 
2022-12-22T02:30:46.456615-0500 info:             "Profile       : Standard Application Server", 
2022-12-22T02:30:46.456663-0500 info:             "OS            : Windows Server 2016 Standard Edition", 
2022-12-22T02:30:46.456718-0500 info:             "MachineType   : VMware Virtual Platform", 
2022-12-22T02:30:46.456767-0500 info:             "Model         : VMware, Inc.", 
2022-12-22T02:30:46.456816-0500 info:             "ServerAppCode : TT00", 
2022-12-22T02:30:46.456866-0500 info:             "", 
2022-12-22T02:30:46.456916-0500 info:             "", 
2022-12-22T02:30:46.456977-0500 info:             ""
2022-12-22T02:30:46.457027-0500 info:         ]
2022-12-22T02:30:46.457079-0500 info:     }

This looks to me more like a logo. I have used also the win_command module with nologo and came up with same result:

win_command: powershell -noninteractive -nologo -command  "get-ChildItem -path $env:realProcessesFolder -Filter *.ps1 -Recurse -File -Name -Depth 0" 

It would be great if you would have any suggestions. Many thanks!

Compo
  • 36,585
  • 5
  • 27
  • 39
Codrin
  • 1
  • Hi Codrin welcome to SO. That one's a toughie, but since searching both SO and the Internet for `ServerAppCode` produces only your question, I'm guessing [`args: { no_profile: true }`](https://docs.ansible.com/ansible/7/collections/ansible/windows/win_shell_module.html#parameter-no_profile) may interest you, although I don't know the powershell ecosystem enough to know whether `powershell -noninteractive` should have worked. I'd strongly recommend `ansible-playbook -vvvv` and see if you can spot anything weird. Good luck! – mdaniel Dec 30 '22 at 01:44
  • I also draw your attention to [`win_find:`](https://docs.ansible.com/ansible/7/collections/ansible/windows/win_find_module.html#synopsis) which is the more ansible-y way of doing that stuff – mdaniel Dec 30 '22 at 01:46
  • It might be a policy issue. What if you were to add this flag / switch as well: `-ExecutionPolicy unrestricted` ? You would add it after `-nologo`. Or, if that doesn't work for some reason, you could try to run this `set-executionpolicy remotesigned` in Powershell, and then try your command as you would normally do it. However, **before you do any that**, be sure to [read more](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.3) about what they do. – FiddlingAway Jan 01 '23 at 14:46

0 Answers0