Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send MailMessage Powershell Script CSV as attachment

Posted on 2013-12-18
1
Medium Priority
?
3,088 Views
Last Modified: 2013-12-18
I have a powershell script that generates a csv file.  I want to have this csv file e-mailed as an attachment.  how can I accomplish this by either integrating the instruction to the existing script, or creating another script to send the csv file.  Below is the script. Thank you.

$Mailboxes = Get-Mailbox -Filter {RecipientTypeDetails -eq "UserMailbox"} -ResultSize Unlimited
$Output = @()
ForEach ($Mailbox in $Mailboxes) {
 # Get the name of the calendar folder
 $Calendar = (($Mailbox.PrimarySmtpAddress.ToString())+ ":\" + (Get-MailboxFolderStatistics -Identity $Mailbox.DistinguishedName -FolderScope Calendar | Select-Object -First 1).Name)
 $Permissions = Get-MailboxFolderPermission -Identity $Calendar
 ForEach ($Permission in $Permissions) {
  $Permission | Add-Member -MemberType NoteProperty -Name "Mailbox" -value $Mailbox.DisplayName
  $Output = $Output + $Permission
 }
}
$Output | Select-Object Mailbox, User, {$_.AccessRights}, IsValid | Export-Csv -Path C:\CalendarPermissions.csv -NoTypeInformation

Open in new window

0
Comment
Question by:fireguy1125
1 Comment
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39727529
Just use Send-MailMessage.  You may have to add some parameters (like -credential or -port) depending on your mail server.  Check out the help for info on parameters.  Here's the basic format...
Send-MailMessage -To "someone@company.com" -From "script@company.com" -Subject "here's the file" -Body "file is attached" -Attachments "C:\CalendarPermissions.csv" -SmtpServer "smtp.company.com"

Open in new window

0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question