Powershell - an empty pipe element is not allowed

Solution 1:

A foreach loop doesn't ouput to the pipeline. You can make it do that by making the loop a sub-expression:

$apps = Import-CSV apps.csv
$computers = Import-CSV compobj.csv
$(foreach($computer in $computers) {    
    $computerLob = $computer.lob
    $lobApps = $apps | ? {$_.lob -eq $computerLob}
    foreach($app in $lobApps){
       $appLocation = $app.location
       $installed=Test-Path "\\$computerHostname\$appLocation"
       $computerHostname = $computer.hostname     
       $results = new-object psobject -property @{Computer=$computer.hostname;App=$app.appname;Installed=$installed} | select Computer,App,Installed 
       $results 
    } 
}) | Export-csv "results.csv" -NoTypeInformation

Solution 2:

I believe the problem you are having is around the use of foreach and the the pipeline, you are processing your items in the foreach statement but still expecting them to be on the pipeline.

This is a common error and is explained in more detail in the article Essential PowerShell: Understanding foreach and Essential PowerShell: Understanding foreach (Addendum).

You should be able to achieve what you want like this:

$apps = Import-CSV apps.csv
$computers = Import-CSV compobj.csv
$computers | foreach {
    $computer = $_
    $computerLob = $computer.lob
    $lobApps = $apps | ? {$_.lob -eq $computerLob}
    $lobApps | foreach {
       $app = $_
       $appLocation = $app.location
       $installed=Test-Path "\\$computerHostname\$appLocation"
       $computerHostname = $computer.hostname     
       new-object psobject -property @{Computer=$computer.hostname;App=$app.appname;Installed=$installed} 
    } 
} | Export-csv "results.csv" -NoTypeInformation