# Help with creating csv file

**URL:** <https://forums.powershell.org/t/help-with-creating-csv-file/19087>\
**Category:** PowerShell Help\
**Created:** [April 14, 2022, 10:15am UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087 "2022-04-14T10:15:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maximus3255](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/maximus3255/32/2234_2.png) [@Maximus3255](https://forums.powershell.org/u/Maximus3255)\
**Post date:** [April 14, 2022, 10:15am UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087/1 "2022-04-14T10:15:49Z")

</div>

Hello, I need help with outputting the information from a test-connection to a csv file. I would like the file to display the ip,result but it only displays the result to the file.

```auto
$computer = Get-Content "$PSScriptRoot\Computers.txt"

Test-Connection -ComputerName $computer -count 1 -Quiet | Out-File $PSScriptRoot\Results.csv

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [April 14, 2022, 11:28am UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087/2 "2022-04-14T11:28:56Z")

</div>

If you carefully (re-)read the help for `Test-Connection` you will learn that the cmdlet only returns `True` or `False` when you specify the parameter `-Quiet`. 😉

> **[Test-Connection (Microsoft.PowerShell.Management) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-connection?view=powershell-5.1)**
>
> The Test-Connection cmdlet sends Internet Control Message Protocol (ICMP) echo request packets, or pings, to one or more remote computers and returns the echo response replies. You can use this cmdlet to determine whether a particular computer can be...

So you have to omit the parameter `-Quiet` and you should use `Export-Csv` instead of `Out-File` for the output.

Try it his way:

```auto
$computer = Get-Content "$PSScriptRoot\Computers.txt"

Test-Connection -ComputerName $computer -Count 1 |
    Select-Object -Property Source, Destination, IPV4Address |
        Export-Csv -Path $PSScriptRoot\Results.csv 

```

---

<div class="post-metadata">

**Author:** ![Maximus3255](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/maximus3255/32/2234_2.png) [@Maximus3255](https://forums.powershell.org/u/Maximus3255)\
**Post date:** [April 15, 2022, 3:57am UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087/3 "2022-04-15T03:57:04Z")

</div>

Oh didn’t notice that. 😅

Also, as is your code you gave me to try doesn’t export the info you put for Select-Object. I did run the code without Select-Object and notice that if a computer didn’t responded it wouldn’t export it. Probably because it didn’t responded/is an error. Would I need to create a forEach, if, else thing?

Also, how do I write it so when it exports the file it outputs the day it was ran, plus the amount of time it was ran that day. Something like Results\_Today Date\_00XX.csv when exported

---

<div class="post-metadata">

**Author:** ![Kira-Shadow](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@Kira-Shadow](https://forums.powershell.org/u/Kira-Shadow)\
**Post date:** [April 15, 2022, 8:25am UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087/4 "2022-04-15T08:25:15Z")

</div>

Probably worth noting that Test-Connection has changed between powershell 5.1 and 7.2.2

and also doesn’t return a response if the host name is not found

This is powershell 7.2.2 (only one error)

```auto
PS C:\Users\ ***** \Desktop> Test-Connection somerubbishwebsite.com
Test-Connection: Testing connection to computer 'somerubbishwebsite.com' failed: Cannot resolve the target name.
PS C:\Users\ ***** \Desktop>

```

and on 5.1 you get 4 errors like this

```auto
Test-Connection : Testing connection to computer 'somerubbishwebsite.com' failed: No such host is known
At line:1 char:1
+ Test-Connection somerubbishwebsite.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (somerubbishwebsite.com:String) [Test-Connection], PingException
    + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand

```

and nothing is sent down the pipeline, so use a try/catch and create a valid response to log in the CSV file

---

<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:18pm UTC](https://forums.powershell.org/t/help-with-creating-csv-file/19087/5 "2024-05-16T20:18:05Z")

</div>


