# Yet another empty pipe element error trying to export-csv

**URL:** <https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168>\
**Category:** PowerShell Help\
**Created:** [April 8, 2016, 9:51am UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168 "2016-04-08T09:51:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bob-king](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@bob-king](https://forums.powershell.org/u/bob-king)\
**Post date:** [April 8, 2016, 9:51am UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168/1 "2016-04-08T09:51:13Z")

</div>

Hi,

Following the thread “another-empty-pipe-error-when-export-csv-used/#post-10028”, I tried to use Dave Wyatt’s second option of “force a foreach loop to pipe its results somewhere (placing the loop into a subexpression, and piping the results of the subexpression to the next command)” and derived the following to see which of our organizations servers are no longer in DNS. Unfortunately all I get is the screen display (helpful) and an empty file (not so much.):

```
$Names = import-csv -Path "C:\temp\AD_servers.csv" | % {$_.Name}
$(
Foreach ($name in $Names)
{
    $Addresses = $null
    try {
        $Addresses = [System.Net.Dns]::GetHostAddresses("$Name").IPAddressToString
    }
    catch { 
        $Addresses = "Server IP cannot resolve."
    }
    foreach($Address in $addresses) {
        write-host "$Name,"$Address
    }
}
) |export-csv "C:\temp\result.csv"
```

Suggestions?

Thanks,  
-Bob King

---

<div class="post-metadata">

**Author:** ![rdtechie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rdtechie/32/273_2.png) [@rdtechie](https://forums.powershell.org/u/rdtechie)\
**Post date:** [April 8, 2016, 10:41am UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168/2 "2016-04-08T10:41:45Z")

</div>

Try this:

```
$Names = Import-Csv -Path 'C:\temp\servers.csv' | ForEach-Object -Process {$_.Name}

@(
    Foreach ($name in $Names) {
        $Addresses = $null
       
        Try {$Addresses = [System.Net.Dns]::GetHostAddresses("$name").IPAddressToString}
        
        Catch {$Addresses = 'Server IP cannot resolve.'}
        
        Foreach($Address in $Addresses) {
            [pscustomobject] @{
                Name = $name
                IPAddress = $Address
            }
        }
    }
) | Export-Csv -Path 'C:\temp\result.csv' -NoTypeInformation
```

This works because I’m passing an object to Export-Csv. You used Write-Host; this only puts text in the console. Nothing else. So there is no input for Export-Csv.

---

<div class="post-metadata">

**Author:** ![bobmccoy](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bobmccoy/32/650_2.png) [@bobmccoy](https://forums.powershell.org/u/bobmccoy)\
**Post date:** [April 8, 2016, 11:17am UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168/3 "2016-04-08T11:17:16Z")

</div>

Richard’s correct. Read the OUTPUTS section of the Write-Host help file. It tells you that it empties the pipeline, that their is nothing left after that.

---

<div class="post-metadata">

**Author:** ![rdtechie](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rdtechie/32/273_2.png) [@rdtechie](https://forums.powershell.org/u/rdtechie)\
**Post date:** [April 8, 2016, 6:07pm UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168/4 "2016-04-08T18:07:21Z")

</div>

And I forgot to mention, every time you use Write-Host, and I’m quoting Don Jones, you kill a puppy. And we don’t want to kill puppy’s, don’t we? 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/yet-another-empty-pipe-element-error-trying-to-export-csv/6168/5 "2024-05-16T20:41:37Z")

</div>


