Email info from imported .csv file to multiple users

rated by 0 users
This post has 1 Reply | 2 Followers

Not Ranked
Posts 1
Bryson0311 Posted: 11-15-2011 12:40 PM

Hello,

I have to figure out how to email around 200 employees information from a .csv file (cell phone usage info). This is the format of how each user in the file looks when I import it. My Idea was to have powershell search active directory by either name or wireless number and then email the information to them. I have never used powershell before so I know only what I've picked up online the past few days. Any Ideas?

Billing Account Number                           : 012345678
Wireless Number                                    : (713) 555-5555
User Name                                             : ERICK ESPINOZA
Market Cycle End Date                           : Oct 08, 2011
Monthly Service Charges                        : $10.00
Usage Charges                                      : $0.00
Credits, Adjustments & Other Charges  : $0.76
Government Fees and Taxes                 : $0.89
Non-Communications Charges              : $0.00
Voice MOUs                                           : 0
Data Usage                                           : 0
Messaging Events                                 : 0

Top 10 Contributor
Posts 640

Sure. Let's say you wanted to use their Name, and let's assume it's the same as the Name attribute in AD, and that your AD "email" attribute is populated with their e-mail address. My example uses the ActiveDirectory module for Win2008R2/Win7:

Import-Module ActiveDirectory
$users = Import-CSV filename.csv
foreach ($user in $users) {
  $aduser = Get-ADUser -filter {name -eq $user.name }
  $email = $aduser.email
  Send-MailMessage -BodyAsHTML -Body ($user | ConvertTo-HTML) -To $email -From "whoever@company.com" 

That should be the basics. There are other options on Send-MailMessage you might have to set, like the mail server info - read the cmdlet's help for information on those. Obviously, if you need to pull information from a different AD attribute (you mentioned phone number), then you'd modify the -filter parameter. I'm not trying to put this out as something that will guaranteed-work in your situation - but it's the basic approach you could consider. I'm also not saying you won't have to learn anything else - because you will - in order to make everything work. Again, just trying to get you started here.

Note that there are some caveats on the ActiveDirectory module if you don't have any R2 domain controllers; you could do something substantially similar with the Quest AD cmdlets, also, which are more broadly compatible.

Page 1 of 1 (2 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.