GetSystemSoftware.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
    }
}