Description of specify ip addresses


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 = “”
$To = (“”)
$SMTPServer = “”
$SMTPPort = “587”
$User = “”
$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


welcome to the 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: - ping ok - London - ping ok - London - ping ok - London - ping ok - London - ping ok - Paris - ping lost - Paris - ping lost - Paris - ping lost - Paris - ping ok - Moscow - ping ok - Moscow - ping ok - Moscow - 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.