Here is a set of samples I used to do a common task in my scripting life. This go around I wanted to use Powershell.
A) Create a script to send emails in powershell
1) Open Powershell type set-executionpolicy Unrestricted
‘This allows scripts to be run’
‘You’ll want to also look at using RemoteSignedType
2) Type Notepad myscript.ps1
3) Paste sample code and save in myscript.ps1
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpServer = “localhost”
$From = “Friendly Reminder <[email protected]>”
$To = [email protected]
$Title = “Subject Matter”
$Body = “Body Text”
B) Testing Script
1) Type ./myscript.ps1
‘Verify you receive the email.
C) How to schedule a powershell script in Windows Task Scheduler
1) Create a new scheduled task.
‘The syntax is to execute the script is:
powershell -command “& ‘SomeDirmyScript.ps1′”
2) Set the script to run as your normal task scheduler accounts.
3) Execute task, verify you receive the email
Hope this helps,