Avatar of rdefino
Flag 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 undefined
Last Comment

8/22/2022 - Mon
Chris Dent

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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.
Your help has saved me hundreds of hours of internet surfing.