Last active
July 23, 2024 06:30
-
-
Save gabriel-vanca/058d63fcf4c41957c010bb12b8fff313 to your computer and use it in GitHub Desktop.
Get-SystemSoftware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
#> | |
param( | |
[string]$ComputerName = $env:computername, | |
[ValidateSet('Registry','WMI')] | |
[string]$QueryType | |
) | |
If (!($QueryType)){$QueryType='WMI'} | |
$ComputerSoftware = @() | |
IF ($QueryType -eq "Registry"){ | |
IF ($ComputerName -ne $env:computername){[array]$uniReg = Invoke-CommandName {Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" | Get-Item | Get-ItemProperty}}else{ | |
[array]$uniReg = 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 | |
$RegPath = $item.pspath -replace "Microsoft\.PowerShell\.Core\\Registry\:\:","" | |
$ComputerSoftware += [pscustomobject]@{ | |
Name = $Name | |
Version = $Version | |
Publisher = $Publisher | |
InstallDate = $InstallDate | |
InstallSource = $InstallSource | |
UninstallString = $UninstallString | |
RegPath = $RegPath | |
} | |
} | |
} | |
IF ($ComputerName -ne $env:computername){[array]$uniReg = Invoke-CommandName {Get-ChildItem -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-Item | Get-ItemProperty}}Else{ | |
[array]$uniReg = 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 | |
$RegPath = $item.pspath -replace "Microsoft\.PowerShell\.Core\\Registry\:\:","" | |
$ComputerSoftware += [pscustomobject]@{ | |
Name = $Name | |
Version = $Version | |
Publisher = $Publisher | |
InstallDate = $InstallDate | |
InstallSource = $InstallSource | |
UninstallString = $UninstallString | |
RegPath = $RegPath | |
} | |
} | |
} | |
$ComputerSoftware | |
} | |
IF ($QueryType -eq "WMI"){ | |
IF ($ComputerName -ne $env:computername){$SFInfo = get-ciminstance Win32_ProductName}else{ | |
$SFInfo = get-ciminstance Win32_Product | |
} | |
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 | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment