I keep receiving the following error message - "An empty pipe element is not allowed" whenever I try to pipe out my results to a csv file. Any idea why this might be happening?
$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
I've tried doing this:
$results | Export-csv "results.csv" -NoTypeInformation
within the foreach loop but it only returns the last record.
Export-csv
one object at a time remember to add the-Append
switch. This should allow you to identify which data is causing the problem. PS. why are you using aselect
on a newPSObject
: that's just wasting cycles.New-Object PSObject …
, there is no need to perform theSelect
(it just creates a new PSObject with the named properties... which is repeating what theNew-Object
just did).