Get-InstalledWin32Program.psm1

function Get-InstalledWin32Program
{
<#
.Synopsis
   Command to get all the installed programs
.DESCRIPTION
   Using this command you can give multiple computer names as an input along with credential(optional) to fetch list of installed programs.
.EXAMPLE
<#
.Synopsis
   Command to read the stealth client dashboard exe file information
.DESCRIPTION
   Using this command you can check the stealth client version information
.EXAMPLE
    Get-StealthClientVersionInfo -ComputerName localhost
.EXAMPLE
    Get-StealthClientVersionInfo -ComputerName localhost -Credential (Get-Credential)
.INPUTS
   1. Computername
   2. Credential as an optional input
.OUTPUTS
   List of installed programs
.COMPONENT
   Operating system
#>

    [CMDLetBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [string[]]$ComputerName,

        [Parameter(Mandatory=$false)]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [pscredential]$Credential
    )
    [int]$i = 0
    [int]$max = @($ComputerName).Count
    [Array]$stealthSoftwareJobs = @()
    foreach($computer in $ComputerName)
    {
        Write-Progress -Activity "Fetching Stealth client information" -Status "InProgress" -Id 0 -PercentComplete (($i/$max)*100) -CurrentOperation "Working on $computer :: $i/$max" -Completed:$false
        $session = $null
        try
        {
            if($PSBoundParameters.ContainsKey("Credential"))
            {
                $session = New-PSSession -ComputerName $computer -Credential $Credential -ErrorAction Stop
            }
            else
            {
                $session = New-PSSession -ComputerName $computer -ErrorAction Stop
            }
            $stealthSoftwareJobs+= Invoke-Command -Session $session -ScriptBlock{ Get-WmiObject -Class Win32_InstalledWin32Program -ErrorAction Stop } -ErrorAction Stop -AsJob
        }
        catch
        {
            Write-Error $_.ToString() -ErrorAction Continue
        }
        $i++
    }
    if($stealthSoftwareJobs.Count -gt 0)
    {
        $results = $stealthSoftwareJobs | Receive-Job -Wait -AutoRemoveJob -Force
        Get-PSSession | Remove-PSSession
        Write-Output $results
    }
    Write-Progress -Activity "Fetching Stealth client settings.xml information" -Status "Completed" -Id 0 -PercentComplete 100 -CurrentOperation "" -Completed:$true
}