从主机名解析IP地址并将结果打印到Excel文件

时间:2016-05-25 12:00:24

标签: powershell

$servers = Get-Content "C:\Users\TEMP\Desktop\test.txt" 
$results = @()

foreach ($server in $servers) {
   [System.Net.Dns]::GetHostAddresses($server)
}

$result.servername = $server
$results += $result

$results | Export-Csv "C:\Users\adcops\Desktop\windows\serversandips.csv"

1 个答案:

答案 0 :(得分:0)

试试这个

Get-Content 'C:\Users\TEMP\Desktop\test.txt' | % {
    [pscustomobject]@{
        Server = $_
        IP = [System.Net.Dns]::GetHostAddresses($_) -join '; '
    }
} | Export-Csv 'C:\Users\adcops\Desktop\windows\serversandips.csv' -NoTypeInformation