$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"
答案 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