July 17, 2020 at 8:38 am #243086ParticipantTopics: 2Replies: 2Points: 17Rank: Member
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.PowerShell123456789101112[crayon-5f6b8decb07f9366579243 inline="true" ]Start-Process 'C:\windows\system32\notepad.exe'$Username = '[email protected]'$Password = '!pippo100'$Secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force$Mycreds = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)$From = "IFE1@localdomain.it"$Cc4 = "email@example.com"$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 OnSuccessStop-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.
July 17, 2020 at 9:15 am #243098ParticipantTopics: 7Replies: 2458Points: 6,439Rank: Community MVP
Marco, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.
When you post code, error messages, sample data or console output format it as code, please.
In the “Text” view you can use the code tags “CODE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
Thanks in advance.
I’d recommend to use some other steps to “indicate” the progress of your script than opening an interactive application like notepad. You might write a file or output a sound for example.
And it is not the best idea (actually a really bad idea) to place a password in your script. I hope you do just for testing purposes. You should run the scheduled task with the according account instead.
- You must be logged in to reply to this topic.