Public/Application/Get-ApplicationInstalled.ps1

<#
Copyright © 2024 Integris. For internal company use only. All rights reserved.
#>


FUNCTION Get-ApplicationInstalled {
    <#
    .SYNOPSIS
    Retrieves a list of installed applications from the registry.
 
    .DESCRIPTION
    The Get-ApplicationInstalled function queries the registry for installed applications on both 32-bit and 64-bit systems. It returns the results sorted by the application name.
 
    .PARAMETER Notable
    If specified, filters the results to include only notable applications.
 
    .EXAMPLE
    Get-ApplicationInstalled
 
    .EXAMPLE
    Get-ApplicationInstalled
 
    .NOTES
    Ensure you have the necessary permissions to access the registry.
    #>


    [CmdletBinding()]
    PARAM (
        [STRING]$Name = "*",
        [SWITCH]$ExactMatch = $false
    )

    FUNCTION Convert-ToVersion {
    PARAM (
        $VersionString
    )

    TRY {
        $VersionString = $VersionString.Replace("v","")
        $VersionString = $VersionString -Split '\.'

        SWITCH ($VersionString.Count) {
            0 { RETURN $Null }
            1 { $Version = "$($VersionString[0])" }
            2 { $Version = "$($VersionString[0]).$($VersionString[1])" }
            3 { $Version = "$($VersionString[0]).$($VersionString[1]).$($VersionString[2])" }
            Default { $Version = "$($VersionString[0]).$($VersionString[1]).$($VersionString[2]).$($VersionString[3])" }
        }

        RETURN [VERSION]$Version
    } 
    CATCH {
        RETURN $null
    }
}

    $Results = @()
    $Apps = @()
    $Apps += Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit
    $Apps += Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"             # 64 Bit


    FOREACH ($App in $Apps) {

        

        IF ($App.DisplayName -eq "" -or $App.DisplayName -eq $Null) { continue }
        TRY { $InstallDate = ([DateTime](($App.InstallDate).SubString(4,2)+"/"+($App.InstallDate).SubString(6,2)+"/"+($App.InstallDate).SubString(0,4))).ToString("MM/dd/yy") } Catch { $InstallDate = "" }
          
        $Results += New-Object PSObject -WarningAction SilentlyContinue -Property @{
            PSTypeName = 'IntegrisPowerShell.ApplicationInstalled'
            Name = $App.DisplayName
            Publisher = $App.Publisher
            Version = (Convert-ToVersion $App.DisplayVersion)
            InstallDate = $InstallDate
            UninstallCommand = $App.UninstallString
        }
    }
 
    IF ($ExactMatch) { RETURN $Results | Where-Object { $_.Name -like "$($Name)" } | Sort-Object Name }
    ELSE { RETURN $Results | Where-Object { $_.Name -like "*$($Name)*" } | Sort-Object Name }
}