Remote query for certain software and get CSV output?

I mostly been playing with command line and just started to figure out PowerShell. So far I have managed to get this script working with the help of google, but I am unable to figure out how to get the output into an CSV file instead of a text file. It would make things easier for me if I could get it into a CSV and maybe convert into an excel format afterwards. I had seen some commands for that while looking over google results. For starters, how would I get the CSV file working instead of a normal text file?

$Computers = Get-Content 'MachineList.txt'
$ProgramList = Get-Content 'ProgramList.txt'
$Date = Get-Date -Format MMM-dd-yyyy:HH.mm

ForEach ($Computer in $Computers){

# Test connection to remote machine
if (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet))
{
# Display a message in the console if no response and output results to the log
Write-Host "$Computer" " | " "Offline" " | " "$Date" -ForegroundColor Red -BackgroundColor Black
"$Computer" + " | " + "Offline" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append
}

Else

{

ForEach ($Program in $ProgramList){

# Providing the machine is reachable
# Checks installed programs for products that contain provided keywords in the name
.\Set-WinRM.ps1 -Mode enable -ComputerName $Computer
Function Get-InstalledApps
{ Invoke-Command -ComputerName $Computer -ScriptBlock {
if ([IntPtr]::Size -eq 4) {
$Regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
} Else {
$Regpath = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
}
Get-ItemProperty $Regpath | .{Process{If($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName
}
}
$Result = Get-InstalledApps | Where {$_.DisplayName -like "*$Program*"}

# Display a message in the console and output results to the log
If ($Result) {
Write-Host "$Computer" " | " "$Program" " | " "Installed" " | " "$Date" -ForegroundColor Green -BackgroundColor Black
"$Computer" + " | " + "$Program" + " | " + "Installed" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append
} Else {
Write-Host "$Computer" " | " "$Program" " | " "NOT Installed" " | " "$Date" -ForegroundColor Yellow -BackgroundColor Black
"$Computer" + " | " + "$Program" + " | " + "NOT Installed" + " | " + "$Date" | Out-File -FilePath "VerificationLog.txt" -Append
}
}
.\Set-WinRM.ps1 -Mode disable -ComputerName $Computer
# End of Else
}
# End of ForEach
}

In order to get results to a CSV, or really to do anything as far as analysis or export, Powershell typically works with a PSObject. If you create a common object schema, then everything has the same properties. This is untested, but this should be closer to what you are looking for:

#The computername should be passed to the function as a parameter, not referenced as an external variable Function Get-InstalledApps { param ( $ComputerName )
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
    if ([IntPtr]::Size -eq 4) {
        $Regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    } 
    else {
        $Regpath = @(
            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        )
    }
    Get-ItemProperty $Regpath | 
    .{Process{If($_.DisplayName -and $_.UninstallString) { $_ } }} | 
    Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |
    Sort DisplayName
}

}

$Computers = Get-Content ‘MachineList.txt’
$ProgramList = Get-Content ‘ProgramList.txt’
$Date = Get-Date -Format MMM-dd-yyyy:HH.mm

$results = foreach ( $Computer in $Computers ){
if (!(Test-Connection -ComputerName $Computer -Count 1 -Quiet)) {
[pscustomobject]@{
Computername = $Computer
Filter = $null
DisplayName = ‘OFFLINE’
Publisher = $null
InstallDate = $null
DisplayVersion = $null
UninstallString = $null
QueryDate = $Date
}
}
else {

    .\Set-WinRM.ps1 -Mode enable -ComputerName $Computer
    #This should be outside the loop as the function is returning ALL software, so you just need to do it once
    $apps = Get-InstalledApps -ComputerName $Computer

    #Loop through the apps to see if they exist in the results returned from query
    foreach ( $Program in $ProgramList ){
        $appQuery = $apps | Where {$_.DisplayName -like "*$Program*"}

        if ($appQuery) {
            [pscustomobject]@{
                Computername    = $Computer
                Filter          = $Program
                DisplayName     = $appQuery.DisplayName
                Publisher       = $appQuery.Pubilisher
                InstallDate     = $appQuery.InstallDate
                DisplayVersion  = $appQuery.DisplayVersion
                UninstallString = $appQuery.UninstallString
                QueryDate       = $Date
            }
        } 
        else {
            [pscustomobject]@{
                Computername    = $Computer
                Filter          = $Program
                DisplayName     = 'NOT_INSTALLED'
                Publisher       = $null
                InstallDate     = $null
                DisplayVersion  = $null
                UninstallString = $null
                QueryDate       = $Date
            }
        }
    }

    .\Set-WinRM.ps1 -Mode disable -ComputerName $Computer
}

}

This allows you to filter to determine outcomes with DisplayName.