you need something like this:
- ansible.windows.win_shell: 'Get-WmiObject -Class Win32_Product | Select-Object Name, Version'
Querying Win32_product isn't a good idea. It can take a long amount of time because it will result in basically every software package revalidating itself, in some rare cases, it can break things.
You might want to query the registry instead, which is a more verbose, but has fewer side-effects.
---
- hosts: windows_hosts
tasks:
- name: installed software
win_shell: |
$items=New-Object System.Collections.ArrayList
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallLocation,
@{Name='Arch' ; Expression={'x64'}} | ForEach-Object {
$items.Add($_) | Out-Null
}
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallLocation,
@{Name='Arch' ; Expression={'x86'}} | ForEach-Object {
$items.Add($_) | Out-Null
}
$items | Select-Object DisplayName, DisplayVersion, Publisher,
Arch, InstallLocation | ConvertTo-JSON
args:
no_profile: yes
register: installed_software
- name: display installed software
debug:
var: installed_software.stdout