PS script goes to the last line of a CSV file, skipping the rest
hi all
i have script generating csv file, clean , want send e-mail recipients. problem is, script goes directly last line , sends last name only...
(get-content c:\users\public\documents\interactivegroup.csv) | % {$_ -replace '"', ""} | out-file -filepath c:\users\public\documents\interactivegroupemail.csv -force -encoding ascii# email fields
$users = import-csv $importfile | select *
foreach($user in $users)
{
$emailaddress = $user.'e-mail'
$displayname = $user.'user full name'
$computer = $user.'machine'
}
$write = "emailing account " + $emailaddress + " -->"
write-host $write
$mail = new-object system.net.mail.mailmessage
$mail.from = $emailfrom
$mail.to.add($emailaddress)
$mail.cc.add($emailcc)
$mail.subject = $emailsubject
$mail.isbodyhtml = $true
$mail.body = $body
$smtp = new-object system.net.mail.smtpclient
$smtp.host = $emailserver
$smtp.send($mail)
write-host ""
trap
{
break;
}
the csv file looks this
user full name,e-mail,machinefirst last ,flast@mydomain.com,t-123456
first last ,flast@mydomain.com,t-789654
first last ,flast@mydomain.com,b-698753214
tia
start this. don't complicate life.
$users = import-csv $importfile foreach($user in $users){ write-host "emailing account $($user.'e-mail')" send-mailmessage -from $emailfrom -to $user.'e-mail' -subject $emailsubject -bodyashtml -body $body -smtpserver $smtpserver }
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment