Solved

Send MailMessage Powershell Script CSV as attachment

Posted on 2013-12-18
1
2,466 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 39

Accepted Solution

by:
footech earned 500 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Questions about DHCP migration 5 61
Exchange 2010 internal URLs 2 40
set-aduser powershell command issue 2 30
Really super easy powershell question 3 25
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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