sending report as an attachment after exporting into CSV format

This post was originally published on this site

Hi All,


I want to send the report over email as an attachment after exporting the report into csv format. Any pointers or help will be much appreciated.


Note:- I’ll send the data store report on a regular basis through window tasks scheduler.



Get-Datastore |

Select-Object Name,


    @{N = ”FreespaceGB”; E = { “{0:n2}” -f ($_.FreespaceGB) } },






    @{N = ”Provisioned”; E = { “{0:n2}” -f ($_.CapacityGB – $_.FreespaceGB + ($_.extensiondata.summary.uncommitted / 1GB)) } },



    @{N = ‘Used Space(%)’; E = { [math]::Round((($_.CapacityGB – $_.FreeSpaceGB) / $_.CapacityGB * 100), 1) } } |



Export-Csv -path c:Tempdsreport.csv -NoTypeInformation -UseCulture


Send-MailMessage -From ‘User01 ‘ -To ‘, ‘User03 ‘ -Subject ‘Sending the Attachment’ -Body “Forgot to send the attachment. Sending now.” -Attachments .C:TempDSreport.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer ‘’





Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.