On Friday, January 21, 2022 at 12:41:10 PM UTC-8 [email protected] wrote:
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.

- 
https://docs.microsoft.com/en-US/troubleshoot/windows-server/admin-development/windows-installer-reconfigured-all-applications
- https://gregramsey.net/2012/02/20/win32_product-is-evil/

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
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1a5cd2a0-9305-4ceb-81f8-9606a1fa2720n%40googlegroups.com.

Reply via email to