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 : 012345678Wireless Number : (713) 555-5555User Name : ERICK ESPINOZAMarket Cycle End Date : Oct 08, 2011Monthly Service Charges : $10.00Usage Charges : $0.00Credits, Adjustments & Other Charges : $0.76Government Fees and Taxes : $0.89Non-Communications Charges : $0.00Voice MOUs : 0Data Usage : 0Messaging Events : 0
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.csvforeach ($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.