I don´t know how I can create a log file for my script in order to know if the files was created succesfully and then if e-mail was sent.
My script generates a report and then sends it over e-mail.
This is the command that generates my HTML report and send e-mail.
Import-Csv -Delimiter "," "E:\SAM\INFORMES\PRINTERS\Informe_de_consumo_PRINTER1 $(Get-Date -f dd-MM-yyyy)Completo3.csv"
ConvertTo-Html -Head $css -Body "<h1>Informes de consumo para la PRINTER1 </h1>`n<h5>Generado el $(Get-Date -f dd-MM-yyyy) por la SAM</h5>"
Out-File "E:\SAM\INFORMES\PRINTERS\Informe_de_consumo_PRINTER 1 $(Get-Date -f dd-MM-yyyy).html" -Encoding utf8
# This is the command to send e-mail
##example:
$From = "informesconsumo@xxx.es"
$To = "xxxxxx@xxxx.es"
$Bcc = "xxxxxxxxxxx@xxxxx.com","xxxxx@xxx.es"
$Attachment = "E:\SAM\INFORMES\PRINTERS\Informe_de_consumo_PRINTER1 $(Get-Date -f dd-MM-yyyy).csv","E:\SAM\INFORMES\PRINTERS\Informe_de_consumo_PRINTER1 $(Get-Date -f dd-MM-yyyy).html"
$Subject = "Informe de consumo PRINTER 1"
$body = "<font face=arial color=black>This is the report for the PRINTER1</font><br>
$SMTPServer = "smtp.xxxxx.es"
$SMTPPort = "xx"
Send-MailMessage -From $From -To $To -Bcc $Bcc -Subject $Subject -Body $Body -BodyAsHtml -Encoding utf8 -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -Attachments $Attachment
How can I put a log in order to see at the end of the day that the file generated properly and was sended.