Function Get-Apps($ComputerName, $TableView) { $86apps, $64apps = Get-SCCM_Apps $ComputerName #Checks if local computer if ($ComputerName -eq $env:COMPUTERNAME) { $localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller | Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } else { #Checks if pc is online so Invoke doesn't hang on offline pc if (Test-Connection -ComputerName $ComputerName -Count 1) { $localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock { Get-Package -ProviderName Programs -IncludeWindowsInstaller | Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } } } $out = $86apps + $64apps $apps = @() foreach ($item in $out) { $a = New-Object -TypeName PSCustomObject $a.PSObject.TypeNames.Insert(0, 'GetPC.App') Copy-Property -From $item -To $a $apps += $a } # Blank entry for visual break $a = [PSCustomObject]@{ DisplayName = "" } $a.PSObject.TypeNames.Insert(0, 'GetPC.App') $apps += $a # Grab apps that are only returned by local query if ($out) { $localOnly = Compare-Object $localapps $out -Property DisplayName -PassThru | Where-Object {$_.SideIndicator -eq '<='} } else { $localOnly = $localapps } foreach ($item in $localOnly) { $a = New-Object -TypeName PSCustomObject $a.PSObject.TypeNames.Insert(0, 'GetPC.App') Copy-Property -From $item -To $a $apps += $a } if ($TableView) { $apps | Out-GridView -Title "Get-PC Apps - $ComputerName" } else { Write-Output $apps } } 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 } }