From e798c0d68651ad4b9ecbde37a8c6726467faa927 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 14:48:36 -0800 Subject: [PATCH] Tidied up apps --- Get-PC/Private/Apps.ps1 | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Get-PC/Private/Apps.ps1 b/Get-PC/Private/Apps.ps1 index f6d8f4d..2dd97bf 100644 --- a/Get-PC/Private/Apps.ps1 +++ b/Get-PC/Private/Apps.ps1 @@ -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 - } } \ No newline at end of file