How to ping multiple servers and return IP address and Hostnames using batch script?

后端 未结 8 1704
余生分开走
余生分开走 2020-12-28 10:45

So I have to use batch only for this. Basically, the server HOSTNAMES are all listed in a txt file. I used the following code to ping all the servers and di

8条回答
  •  自闭症患者
    2020-12-28 11:44

    Try this

    $servers = Get-Content test.txt
    
    $reg=""
    
    foreach ($server in $servers) 
    
    {
    
    $reg=$reg+$server+"`t"+([System.Net.Dns]::GetHostAddresses($server) | foreach {echo $_.IPAddressToString})+"`n"
    
     }
    $reg >reg.csv
    

提交回复
热议问题