We help IT Professionals succeed at work.

How to dump output to csv file

rdefino
rdefino asked
on
112 Views
Last Modified: 2017-03-30
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
Comment
Watch Question

PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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.