Description of specify ip addresses

Welcome,

I need help, How can i add description to my specify addresses of pings the purpose of their description.
I do script with test-connection command for some devices in my network.
I expect the result with description of ping addresses.
This is my script:

$tableaddresses = gc D:\tableaddresses.txt
$reconnected += $lostpings
$lostpings = $blank

###Configuration of the e-mail server###
$From = “reports@o2.pl”
$To = (“xyz@o2.pl”)
$SMTPServer = “1.2.3.4”
$SMTPPort = “587”
$User = “reports@o2.pl”
$PWord = ConvertTo-SecureString -String “xyzxyz” -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -Argumentlist $User, $PWord

###Perform a task for each of the pings###
$tableaddresses | foreach-object {
$pinging = Test-Connection _ -Count 1 -ea silentlycontinue

if (($pinging) -and ($reconnected -imatch $_)) {
    workagain += "`n $_"
    Write-Host $_ “Work again” -Foregroundcolor Black -Backgroundcolor Cyan
}

elseif (pinging) {
    Write-Host $_ “ping ok” -Backgroundcolor Green
}

else {
    lostpings += "$_ `n"
    Write-Host $_ “ping lost” -Backgroundcolor Black
}

}

###Checking empty variables###
if ($workagain -eq $null) {
Write-Host “variable with arrays that started working again is empty” -Backgroundcolor Red
}
else {
Send-MailMessage -From $From -to $To -Subject “the boards were up” -Body $workagain -BodyAsHtml -SmtpServer $SMTPServer -Port $SMTPPort -Credential ($Credential)
Write-Host “An email has been sent with addresses that are pinging again” -Backgroundcolor DarkMagenta
}
if ($lostpings -eq $null) {
Write-Host “a variable with arrays that have been non-pinging is empty” -Backgroundcolor Red
}
else {
Send-MailMessage -From $From -to $To -Subject “Lost Pings” -Body $lostpings -BodyAsHtml -SmtpServer $SMTPServer -Port $SMTPPort -Credential ($Credential)
Write-Host “An email has been sent with addresses that are not pinging” -Backgroundcolor DarkMagenta
}

###Variable reset###
$workagain = $blank
$reconnected = $blank

Michał,

welcome to the Powershell.org forums.

What kind of description do you expect? Could you show an example?

Unfortunately your code is very hard to read as you’re using Polish terms and variable names. :wink: And it looks like you’re either using functions you declared outside of the code you’re showing or you forgot some $ charachters.

I’m not sure what you mean by description:

What specifically is Test-Connection not providing that you expect? Can you give an example of what you are looking for?

Shouldn’t this:

pingowanie = Test-Connection _ -Count 1 -ea silentlycontinue

Be This:

pingowanie = Test-Connection $_ -Count 1 -ea silentlycontinue

Haven’t seen it when I pasted my code here, a few items were changed - mainly “$” was changed for HTML marker, so i correct code from the mainly comment.
This is my example of result whitch i need:

10.0.0.1 - ping ok - London
10.0.0.2 - ping ok - London
10.0.0.3 - ping ok - London
10.0.0.4 - ping ok - London
10.0.0.5 - ping ok - Paris
10.0.0.6 - ping lost - Paris
10.0.0.7 - ping lost - Paris
10.0.0.8 - ping lost - Paris
10.0.0.9 - ping ok - Moscow
10.0.0.10 - ping ok - Moscow
10.0.0.11 - ping ok - Moscow
10.0.0.12 - ping lost - Moscow

So every 4 pings of the IP is another localization and i need attach it for every of ip addresses.

Test-Connection does not provide these kind of information. You would need to inject them by yourself to the result. If you have a kind of dictionary where you store those information about your network you could combine both informations if you like.

Thank you for reply :slight_smile:
I know, but i need send emails with reports which only information which of them are not responding. I’m sure, that exist commands which connect addresses of the variable “lostpings” with list describing them addresses, but i don’t know them.

I’m not sure that I get what you mean.

Test-Connection -ComputerName 'remoteComputer' -Count 1 -Quiet

This line of code returns either $true or $false and you can use this information to your need.