Link to home
Start Free TrialLog in
Avatar of rdefino
rdefinoFlag for United States of America

asked on

How to dump output to csv file

I have the script below that runs fine, but I cannot get it to dump to a csv file. the output file is created, but it's empty. What am I missing?

Get-Content E:\rdefino\verify_alias\aliases_list.txt | % {$proxy = "smtp:"+$_.tostring().trim(); if(Get-ADObject -Filter {proxyaddresses -eq $proxy} ) {Write-Host "Found: $proxy"} else {Write-Host "Not Found: $proxy"}} | Export-Csv  E:\rdefino\verify_alias\alias_output.csv
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
First of all, I formatted your script:
Get-Content E:\rdefino\verify_alias\aliases_list.txt |
  % {
    $proxy = "smtp:"+$_.tostring().trim()
    if(Get-ADObject -Filter {proxyaddresses -eq $proxy})
      Write-Host "Found: $proxy"
    } else {
      Write-Host "Not Found: $proxy"
  } | Export-Csv  E:\rdefino\verify_alias\alias_output.csv

Open in new window

Chris is correct.
If you really want the text output only, use Write-Output instead of Write-Host, and Out-File instead of Export-CSV.