I am trying to figure out how I can schedule a task to run once a week with task scheduler to copy two files and attach them to an email and email them to a group of people. Is this possible to do? To have a script that will run using power shell grab two files from certain locations and then email them? Would it be similar to what I have below or am I going in the wrong direction?
$ol = New-Object -comObject Outlook.Application
$message = $ol.CreateItem(0)
$message.Recipients.Add("Deployment")
$message.Subject = "Website deployment"
$message.Body = "See attached file"
$file = "K:\Deploy-log.csv, K:\Deploy-log2.csv"
$message.Attachments.Add($file)
Error
Exception calling "Add" with "1" argument(s): "File name or directory name is not valid." At C:\Users\davidb\Desktop\email.ps1:8 char:1 + $message.Attachments.Add($file)
- FullyQualifiedErrorId : ComMethodTargetInvocation
If I take , K:\Deploy-log2.csv
off it will not error but I still do not receive the email either