GetSystemSoftware.psm1

Function Get-SystemSoftware{
    <#
    .SYNOPSIS
    Gather software installed on a local or remote device
    .DESCRIPTION
    Gather Software and information about the software installed on a local or remote device using the registry or WMI
    .PARAMETER ComputerName
    Computer to gather software on
    .PARAMETER QueryType
    Specify how you want to gather the information
    WMI - Gather installed software installed using an msi
    Registry - Pulls the software info from the computer registry, Requires WinRM to be running on the target computer
    .NOTES
    Contact: contact@mosaicmk.com
    Version: 3.2.3
    .LINK
    https://www.mosaicmk.com
    #>

    param(
        [string]$ComputerName = $env:computername,
        [ValidateSet('Registry','WMI')]
        [string]$QueryType
    )

    If (!($QueryType)){$QueryType='WMI'}
    $ComputerSoftware = @()
    IF ($QueryType -eq "Registry"){
        [array]$uniReg = Invoke-Command -ComputerName $ComputerName {Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" | Get-Item | Get-ItemProperty}
        foreach ($item in $uniReg){
            if ($item.DisplayName){
                $Name = $item.DisplayName
                $Version = $item.DisplayVersion
                $Publisher = $item.Publisher
                $InstallSource = $item.InstallSource
                $InstallDate = $item.InstallDate
                $UninstallString = $item.UninstallString
                $ComputerSoftware += [pscustomobject]@{
                    Name = $Name
                    Version = $Version
                    Publisher = $Publisher
                    InstallDate = $InstallDate
                    InstallSource = $InstallSource
                    UninstallString = $UninstallString
                }
            }
        }
        [array]$uniReg = Invoke-Command -ComputerName $ComputerName {Get-ChildItem -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-Item | Get-ItemProperty}
        foreach ($item in $uniReg){
            if ($item.DisplayName){
                $Name = $item.DisplayName
                $Version = $item.DisplayVersion
                $Publisher = $item.Publisher
                $InstallSource = $item.InstallSource
                $InstallDate = $item.InstallDate
                $UninstallString = $item.UninstallString
                $ComputerSoftware += [pscustomobject]@{
                    Name = $Name
                    Version = $Version
                    Publisher = $Publisher
                    InstallDate = $InstallDate
                    InstallSource = $InstallSource
                    UninstallString = $UninstallString
                }
            }
        }
        $ComputerSoftware
    }
    IF ($QueryType -eq "WMI"){
        $SFInfo = Get-WmiObject Win32_Product -ComputerName $ComputerName
        foreach ($item in $SFInfo){
            $Name = $item.Name
            $ID = $item.IdentifyingNumber
            $Publisher = $item.Vendor
            $Version = $item.Version
            $InstallDate = $item.InstallDate
            $InstallSource = $item.InstallSource
            $ComputerSoftware += [pscustomobject]@{
                Name = $Name
                Version = $Version
                ID = $ID
                Publisher = $Publisher
                InstallDate = $InstallDate
                InstallSource = $InstallSource
            }
        }
        $ComputerSoftware
    }
}