Tidied up apps

This commit is contained in:
Zachary Gorman 2025-02-13 14:48:36 -08:00
parent c4f3efa30b
commit e798c0d686

View file

@ -1,11 +1,10 @@
# Assumes 64 bit system, registry keys may be different on 32 bit systems
Function Get-Apps($ComputerName, $CompStatus, $TableView) {
$32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
if ($CompStatus -eq "Online") {
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1
$sblock = {
$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
@ -14,13 +13,14 @@ Function Get-Apps($ComputerName, $CompStatus, $TableView) {
Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru
$apps += Get-Package |
Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru
$apps | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
$apps | Sort-Object 'x86/x64',DisplayName -Unique
}
#Checks if local computer
if ($ComputerName -eq $env:COMPUTERNAME) {
$apps = Invoke-Command -ScriptBlock $sblock
$apps = Invoke-Command -ScriptBlock $sblock | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ }
} else {
$apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock
$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'); $_ }
}
} else {
Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1
@ -36,11 +36,4 @@ Function Get-Apps($ComputerName, $CompStatus, $TableView) {
Write-Output $apps
}
Write-Progress -Activity "Getting apps for $ComputerName" -Completed
}
function Copy-Property ($From, $To) {
$properties = Get-Member -InputObject $From -MemberType NoteProperty
foreach ($p in $properties) {
$To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force
}
}