Good Afternoon r/powershell!
I recently got tasked with sending invoices to ~900 users, prior to me, this was all done manually, but I’m not a fan of copying and pasting that many emails.
I thought I could automate the task with powershell, but I’ve run into a problem – the email I am using sends every invoice to every email in the CSV of $users.
My PS code and sanitized data example are below, could someone take a look and let me know what I’m doing wrong? I’ve googled and bashed my head against this problem for a couple days and I can’t figure it out.
Thanks!
>PS C:usersadmindesktop> $csv = import-csv "test.csv" >> $csv.Number |foreach-object { >> send-mailmessage -from "admin@example.com"` >> -to $csv.Email` >> -subject "Your invoice is ready"` >> -body "This message is to let you know there is an invoice ready for your attention, thanks!"` >> -attachment $csv.attachment` >> -smtpserver mail.example.com >> }
and my data looks like Name Number Email attachment
George Washington 867-5309 george@geocities.com c:usersadmindesktopgwbill
Abraham Lincoln 555-1234 abe@geocities.com C:usersadmindesktopalbill
John Adams 555-6789 jadams@geocities.com C:usersadmindesktopjabill
submitted by /u/superpenguin38
[link] [comments]