Attachment is not being sent via email

Welcome Forums General PowerShell Q&A Attachment is not being sent via email

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
8 months ago.

  • Author
    Posts
  • #95883

    Participant
    Points: 1
    Rank: Member

    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

  • #95886

    Participant
    Points: 1
    Rank: Member

    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
    
  • #96051

    Participant
    Points: 1
    Rank: Member

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

The topic ‘Attachment is not being sent via email’ is closed to new replies.