Good morning everyone, I have a small problem regarding a powershell script and scheduled operations.
The script below should open a notepad process, send an email and close the newly opened process.
If I do it step by step there are no problems everything works correctly if instead I try to insert it a scheduled operation I only get the notification email but the notepad window does not open let alone close.
To do the tests I am using the notepad but this script should stop the running services, restart them automatically and send an email.
Start-Process 'C:\windows\system32\notepad.exe'
$Username = 'info@localdomain.it'
$Password = '!pippo100'
$Secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$Mycreds = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)
$From = "IFE1@localdomain.it"
$Cc4 = "prova@localdomain.it"
$Subject = "Riavvio Servizi IFE1"
$Body = "Email inviata per confermare il corretto riavvio dei servizi su IFE1"
$SMTPServer = "smtp.localdomain.it"
Send-MailMessage -From $From -to $Cc4 -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port 25 -Credential $Mycreds –DeliveryNotificationOption OnSuccess
Stop-process -Name notepad.exe
Would anyone know how to make suggestions?
The password used is fictitious and not the real password of the smpt server.
As for the application to be run I used the notapad because it is the one that has a more immediate visual response.
I don’t understand why the notepad app doesn’t open but the email is sent, being part of the same code.