Get-PC/Get-PC/Private/Apps.ps1

49 lines
2.7 KiB
PowerShell
Raw Normal View History

# Assumes 64 bit system, registry keys may be different on 32 bit systems
Function Get-Apps($ComputerName, $CompStatus, $TableView) {
if ($CompStatus -eq "Online") {
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1
$SHSAppsPath = Join-Path (get-item $PSScriptRoot).Parent.FullName 'Data\SHSApps.json'
$SHSApps = Get-Content $SHSAppsPath | ConvertFrom-Json
$sblock = {
2025-02-13 22:48:36 +00:00
$32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$apps = Get-ItemProperty $32RegPath |
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru
$apps += Get-ItemProperty $64RegPath |
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru |
Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru
$apps += Get-Package |
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru
foreach ($app in ${using:SHSApps}) {
if (Test-Path $app.Path) {
$apps += [PSCustomObject]@{
DisplayName = $app.DisplayName
Computer = $env:ComputerName
}
}
}
2025-02-13 22:48:36 +00:00
$apps | Sort-Object 'x86/x64',DisplayName -Unique
}
#Checks if local computer
if ($ComputerName -eq $env:COMPUTERNAME) {
2025-02-13 22:48:36 +00:00
$apps = Invoke-Command -ScriptBlock $sblock | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
} else {
2025-02-13 22:48:36 +00:00
$apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock |
Select-Object -Property * -ExcludeProperty PSComputerName | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
2024-06-11 18:27:55 +00:00
}
} else {
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1
$86apps, $64apps = Get-SCCM_Apps $ComputerName
$apps = ($86apps + $64apps) | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
2024-06-11 18:27:55 +00:00
}
2024-06-11 18:27:55 +00:00
if ($TableView) {
$apps | Out-GridView -Title "Get-PC Apps - $ComputerName"
}
else {
Write-Output $apps
}
Write-Progress -Activity "Getting apps for $ComputerName" -Completed
2024-06-11 18:27:55 +00:00
}