$results = @() Import-Csv -Path input_dns.csv | foreach { $currentLine = $_ $record = $currentLine.A_Record try { $result = Resolve-DnsName $record -Type A -Server 8.8.8.8 2> $null Write-Host $result.getType().fullname $exportLine = $result | Select-Object -Property Name,Type,IPAddress $exportLine | Add-Member -MemberType NoteProperty -Name "Status" -Value "ok" } catch { Write-Host ("Error with record: {0}" -f $record) $exportLine = New-Object psobject -Property @{ 'Name' = $record; 'Type' = 'A'; 'IPAddress' = ''; 'Status' = 'ko'; } } $results += $exportLine } $results | Export-Csv -Path dnsPreCheck.csv -Delimiter "," -Encoding UTF8 -NoTypeInformation