Ping Computers From File

$names = Get-content "C:\list.txt"
$file = '\\share\pingable.txt'
while ((Test-Path $file))
{
$file = $file.Replace(".txt", "_.txt")
}
foreach($name in $names) {
 if(Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue)
{
Write-Host "$name Is Online" -ForegroundColor Magenta
"$name" >> $file
}
else
{
Write-Host "$name is offline" -ForegroundColor Red
}
}