Today I receive a message from a good friend in Singapore, asking for help on PowerShell. Well, is glad that someone comes to me asking for help on PowerShell. Sorry I could get a little bit excited whenever question on PowerShell. There are many ways to achieve this though, so don’t limit yourself. It is kind of an experimental situation with him on this packet loss detection too. This post is kind of to give you a hint of how you could create your own packet loss detection.
So this is mine but you can modify it,
- This is a constant IP address value (you can include hostname)
-
Try{ #Stop progress if failure to achieve a successful return Test-Connection <IP address> -ErrorAction Stop } Catch{ #Return an error message $ErrorMessage = $_.Exception.Message Write-Host $ErrorMessage }
-
- You can have it in data entry form too
-
#Data Entry of IP address that you wish to test connection, #if connection successful there will be test conenction result 4 times (by default) $IPAddress=Read-Host "IP address" Try{ #Stop progress if failure to achieve a successful return Test-Connection $IPAddress -ErrorAction Stop } Catch{ #Return an error message $ErrorMessage = $_.Exception.Message Write-Host $ErrorMessage }
- Testing how are the result and behavior is. I disconnected from the Internet and an error message return instantly.
-
- For repetitive capability or 24×7, you got to be careful the resource exhaustion. Please check your task manager what is the performance when the PowerShell is running.
- You can even have it to return to send an email using the Send-MailMessage command, you can use default SMTP or your organization SMTP Server (this is a bit tricky)
-
Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>', 'User03 <user03@fabrikam.com>' -Subject 'Sending the Attachment' -Body "Forgot to send the attachment. Sending now." -Attachments .\data.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'smtp.fabrikam.com'
-
Good luck with your testing!
References: