Forum Discussion
Need help with powershell scripting
Hi SLoventhal,
you can try the following options:
Run PowerShell as Administrator:
Ensure that the path to your PowerShell script (e.g., D:\Monday.ps1) is accurate. Use a command like the one below, adjusting the script path:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File \"<Your-Script-Path>\"' -Verb RunAs}"
Sending Email via Gmail:
For sending emails via Gmail, secure connections and proper authentication are necessary. Here's a changed script:
$EmailFrom = "email address removed for privacy reasons"
$EmailTo = "email address removed for privacy reasons"
$Subject = "Email subject"
$Body = "Email body"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object
System.Net.NetworkCredential("username", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Replace "username" and "password" with your Gmail credentials.
Note: If you have 2-step verification enabled on your Gmail account, you’ll need to generate and use an app password (https://support.google.com/accounts/answer/185833?hl=en). Also, you might need to allow less secure apps to access your Gmail account (https://support.google.com/accounts/answer/6010255?hl=en).
smtp - sending email with gmail using powershell - Stack Overflow
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)