Another tricky one! I did a powershell script that successfully extracted list of computers and users that are currently logged to them in a specific Domain )then output data to an Excel sheet with three columns ( Name , Computer and e-mail address) 

Now I need to send each user in spreadsheet an individual e-mail requesting an action on the machines. I have the script below

$emailFrom = me@company.com

$subject= Urgent action on *machine* 

$body = Please return  *Machine* by given time etc etc 
$emailTo= recepient@company.com
$smtpServer = smtp.company.com
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

How do I modify it to perform a loop action and read through the Excel sheet and; 

1)pick out the user's e-mail address
2)add the corresponding  machine in body of the e-mail 
3)Send out e-mails one by one

Many thanks in advance!
Answer Summary:
0 Comments   [ - ] Hide Comments


Please log in to comment

Answer Chosen by the Author


So this isn't really a K1000 question, but PS is fun anyway!

Maybe add something like this? This assumes you have a .csv that has at least these three columns: Name , Computer and e-mail.

$import=import-csv c:\yourdoc.csv
$smtpServer = smtp.company.com
$emailFrom = me@company.com
$subject= "Urgent action on " ## add machine later in the loop

foreach ($person in $import)
$body="Please return $computer by $now.adddays(7)." # 7 days from today, for example.
$smtp=new-object Net.Mail.SmtpClient($smtpServer)

Answered 06/09/2015 by: bknorr
Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity