Author Posts

March 14, 2018 at 10:44 am

Hi Team,

I am learning powershell and have command where I am sending the email to myself along with the attachment. I am able to send the email but attachment is not being sent. Below is the command:

PS C:\JPS> Get-Service -Name B* | Export-Csv C:\JPS\test.csv | Send-MailMessage -To myemail@domain.com -Subject
'Sending Test Attachment' -SmtpServer 'servername' -Attachments test.csv -From myemail@domain.com -Verbose

March 14, 2018 at 10:47 am

As far as I know, it won't work from pipeline. Divide that to to commands

Get-Service -Name B* | Export-Csv C:\JPS\test.csv 
Send-MailMessage -To jatinder.singh@ihsmarkit.com -Subject
'Sending Test Attachment' -SmtpServer 'servername' -Attachments C:\JPS\test.csv -From jatinder.singh@ihsmarkit.com
-Verbose

Or if you want it to be one liner, then

Get-Service -Name B* | Export-Csv C:\JPS\test.csv ; Send-MailMessage -To jatinder.singh@ihsmarkit.com -Subject
'Sending Test Attachment' -SmtpServer 'servername' -Attachments C:\JPS\test.csv -From jatinder.singh@ihsmarkit.com
-Verbose

March 15, 2018 at 2:34 pm

Yes Aapeli, you were right. Thank you so much. Without using |, it worked.