Powershell email

Welcome Forums Pester Powershell email

Viewing 2 reply threads
  • Author
    Posts
    • #101701
      SK
      Participant
      Topics: 6
      Replies: 7
      Points: 0
      Rank: Member

      $File=”gci \\abcd\efgh\ijkl | select -last 1″
      $From = “[email protected]
      $To = “[email protected]
      $Attachment = $File
      $Subject = “Here’s the Email Subject”
      $Body = “This is what I want to say”
      $SMTPServer = “smtp.gmail.com”
      Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -Attachments $Attachment

      This is the error I receive:
      Send-MailMessage : Illegal characters in path.
      At line:1 char:1
      + Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $ …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Send-MailMessage], ArgumentException
      + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SendMailMessage

      What am I doing wrong here?
      Thanks

    • #101920
      Participant
      Topics: 12
      Replies: 38
      Points: 261
      Helping Hand
      Rank: Contributor

      There are a couple of potential pitfalls I can think of:
      1 – Instead of “$Attachment = $File” try “$Attachment = $File.FullName”
      2 – Paste it into a text editor like Notepad++, and see if the encoding is dodgy (try ANSI and UTF)
      3 – Also in Notepad++, try replacing your double qoutes, I find that some text editors change the double quotes so they aren’t compatible with a console.
      Good luck.

    • #110017
      Senior Moderator
      Topics: 9
      Replies: 1265
      Points: 4,582
      Helping Hand
      Rank: Community Hero

      Problem here is

      $File="gci \\abcd\efgh\ijkl | select -last 1"
      
      #it should be
      $File=gci \\abcd\efgh\ijkl | select -last 1 -ExpandProperty FullName
      
      
      when you put everything in double quotes, the whole statement becomes a string.
Viewing 2 reply threads
  • The topic ‘Powershell email’ is closed to new replies.