Complete newbie in Powershell. I do VBA in Access and Excel so I thought this would be easy. Not so much.
I have a txt file of computer names.
I would like to generate a csv the displays:
Computername, IP Address, Ping Status
My first attempt was:
Test-Connection -ComputerName (get-content C:\WMI_Tools\Computerlist.txt) -Count 1 -ea 0 | Select-Object Address,IPV4Address
That works great to give me the active computers but it is lacking a ping status
My next few attempts involved foreach, if/else and Out-file but I can't get all the parts correct.
I found this code from Jaap Brasser here on forum.
Get-Content .\computerlist.txt | ForEach-Object {
if(Test-Connection -ComputerName $_ -Quiet -Count 1) {
New-Object -TypeName PSCustomObject -Property @{
ServerName = $_
'Ping Status' = 'Ok'
}
} else {
New-Object -TypeName PSCustomObject -Property @{
ServerName = $_
'Ping Status' = 'Failed'
}
}
} | Export-Csv C:\WMI_Tools\Get_PingResults.csv
How would I add IP Address?
Ping status is the first column currently.
Howow do I make it so ServerName is the first column?
Thank you.