Hey Guys got this code:
$Comps = Get-Content C:\comps.txt
Foreach ($i in $comps) {
Try
{
Write-Host $i
[System.Net.Dns]::GetHostAddresses("$i") | fl IPAddressToString -ErrorAction stop
}
Catch
{
Write-Host "Computer $i is not accessible `n"
continue
}
}
C:\comps is just a list of computers - I'm getting there last seen IP's from our DNS records - what I would like to do however is instead of printing
Computer Name
<Output of static method> as two seperate lines
I'd much rather create an object with two parameters - Name of computer, and IP address. How can I take the output of the write-host and the output of the static method and place them into one object? This would make formatting much easier and I would be able to export to csv.
Thanks guys.