I have sought an answer in another forum, made some progress, but still haven't managed to get this to work....
I have several Smart Switches controlled by Alexa, running automated routines. Trouble is, that sometimes the SM's become inaccessible to Alexa, so the routine doesn't then do anything - until I happen to check the devices in Alexa and notice the comms failure, then reset.
I have not found any way for Alexa to advise me of the failure, so I looked at other ways and a possible solution seems to be to ping the devices and report ping failures.
Nirsoft's PingInfoView is a likely candidate for the job, but doesn't include the essential ability to send an email to report failures, it is though supposed to be able to use a PowerShell script to send an email...
I have the PingInforView located in C:\Program Files\Nirsoft and the script file in that same folder.
This is the 'failed.ps1' script, with the details adjusted for my details in the first four lines of the script.
++++++++++++++++++++++++++++++++ $Username = "username"; $Password = "password"; $SendTo = "my email address"; $MailServer = "mail server"; $HostName = $args[0]; $IPAddress = $args[1]; $PingStatus = $args[2]; $FailedOn = $args[3];$message = new-object Net.Mail.MailMessage; $message.From = $Username; $message.To.Add($SendTo); $message.Subject = "Failed Ping On $HostName" ; $message.Body = "Information about the failed ping: `r`nHost Name: $HostName`r`nIP Address: $IPAddress`r`nPing Status: $PingStatus`r`nPing Time: $FailedOn";
$smtp = new-object Net.Mail.SmtpClient($MailServer, "25"); $smtp.EnableSSL = $true; $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password); $smtp.send($message);
++++++++++++++++++++++++++++++++++++This line is run by PingInfoView when a failure to reply to ping is detected...
Powershell.exe -executionpolicy remotesigned -File C:\Program Files\Nirsoft\failed.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%"
It is obvious that the line does get run when a deliberate failure is set up, because I see a brief flash of the blue PS Console screen, but no email is sent, or received.
If I open a PS Console and past the above line in, this is the response I get...
PS C:\WINDOWS\system32> Powershell.exe -executionpolicy remotesigned
-File C:\Program Files\Nirsoft\failed.ps1 "%HostName%" "%IPAddress%" "%LastPingStatus%" "%LastFailedOn%" Processing -File 'C:\Program' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again. Windows PowerShell
If I copy and paste the entire contents of the actual script into the PS Console, it runs as expected, an email is sent and received.
I also made sure that 'failed.ps1' was edited in Wordpad and saved as 'all files'. The file is also listed in Explorer as a Powershell Script, so why this complaint when trying to use the script.... 'Processing -File 'C:\Program' failed because the file does not have a '.ps1' extension.' ???