Nslookup Computers From File

$names = Get-content "C:\list.txt"
$file = '\\share\nslook.txt'
while ((Test-Path $file))
{
$file = $file.Replace(".txt", "_.txt")
}
foreach($name in $names)
{
$Addresses = $null
$Addresses = [System.Net.Dns]::GetHostAddresses("$name").IPAddressToString
"$name" >> $file
}
catch{
$Addresses = "Server Ip cannot resolve."
}
foreach($Address in $Addresses){
write-host $name, $Address
}
}