My code:
$Servers = Get-Content -Path "./FULl_List_hosts_all_CSV_V2.txt"
$Array = foreach($Server in $Servers) {
$Server = $Server.Trim()
try {
$DNSCheck = [System.Net.Dns]::GetHostEntry($Server)
# just output an object so it gets collected in variable $Array
[PsCustomObject]@{
'Server name' = $Server # or $DNSCheck.HostName
'IP Address' = ($DNSCheck.AddressList | Where-Object {$_.AddressFamily -eq 'InterNetwork'})[0].IPAddressToString
}
}
catch {
# either do nothing here to skip this server of output a 'n/a' object
[PsCustomObject]@{
'Server name' = $Server
'IP Address' = 'n/a'
}
}
}
# output on screen
$Array | Format-Table -AutoSize
# write to csv
$Array | Export-Csv -Path "./pingstatus.csv" -NoTypeInformation
The Full_List_Hosts has more than 150K hostnames. When I run the shell script it sits there. No doubt loading it all - but is there a way I can make it count up to maybe 200 then pause, write to the csv file then continue? If I do a shorter file - the script takes seconds to complete. Just want to make sure it is truly running. OPen to recomendations. thanks
I tried using a shorter list of hosts in a file. worked fine. I want some indicaton that it is running and not just sitting there with a "dumb look" only to come after HOURS of running and find nothing.