Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $From = "server@server.xxxxx"
- $To = "alert@server.xxxxx"
- $Subject = "There can be only one."
- $Body = "I have got something to say. It is better to burn out than fade away."
- $ipaddress = ipaddress
- $port = port
- $SMTPServer = "smtpserver"
- $SMTPPort = "587"
- $Username = "kurgan"
- $SecurePassword = Get-Content C:\ps\ScheduledTaskUser.txt | ConvertTo-SecureString
- $UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$SecurePassword
- $connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
- if ($connection.Connected) {
- Write-Host "Success"
- }
- else {
- Write-Host "Failed"
- }
- $fail = 0
- for($i = 0; $i -lt 3; $i++){
- if(Test-NetConnection $ipaddress -Port $port -InformationLevel Quiet){"Port Open"}
- {
- "Port Open"
- }
- else{
- $fail ++
- if ($fail -eq 3){
- Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $UserCredential
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement