powershell: sending e-mail with attachments (using a pipe)

$PSEmailServer = "mailsrv"

Get-ChildItem("c:\temp") |
      ForEach {$_.fullname} |
      Send-MailMessage -to "x@regele.org" -from "y@regele.org" -subject "hi" -encoding ([System.Text.Encoding]::UTF8)


  • $PSEMailServer needs to contain the smtp Server
  • ForEach ... $_.fullname is required if files are not in current path


Kommentare

Unknown hat gesagt…
Völlig Sinnfrei (could be done with wmiObject allone, only to show nesting pipes)

Get-Service | Where {$_.Status -eq "Running"} |
Where {$name = $_.name
1 -eq (Get-WmiObject Win32_Service -Filter "Name='$name'" |
where {$_.StartMode -eq "Auto"} |
Measure-Object).Count;
} | FT

Beliebte Posts aus diesem Blog

Powershell snippet to send messages to telegram

using the birt runtime with spring boot and gradle to generate PDF from a Report Design File