Powershell commandline mailing , send mail

Powershell commandline mailing , send mail

statusmailer.ps1 :

$data can be any data you want to send.

$data = Get-ChildItem “\\10.10.102.249\backup\” | sort-object -property @{Expression={$_.LastWriteTime}; Descending=$true} | format-table LastWriteTime,Length,Name -auto | out-string
$emailFrom = “backup@domain.be
$emailTo = “user@domain.be
$subject = “backupverslag LINIX”
$body = $data
$smtpServer = “10.10.10.1”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

 

statusmail.cmd :

powershell -command “& ‘c:\tools\statusmailer.ps1’ “

Leave a Reply

Your email address will not be published.

one × 5 =

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