Function Get-Apps($ComputerName, $TableView) {

    Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1
    $86apps, $64apps = Get-SCCM_Apps $ComputerName

    Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1
    #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
            }
        }
    }
            
    Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from SCCM' -PercentComplete 50 -ParentId 1
    $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

    Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from local query' -PercentComplete 75 -ParentId 1
    # 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
    }
    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
    }
}