如何为各种命令创建 powershell 日志文件

How to create a powershell log file for various commands

我不知道如何为我的脚本创建日志文件,以便了解文件是否已成功创建以及电子邮件是否已发送。

我的脚本生成报告,然后通过电子邮件发送。

这是生成我的 HTML 报告和发送电子邮件的命令。

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

如何放置日志以便在一天结束时查看文件是否正确生成并已发送。

给出的答案没有帮助。我在 Powershell 文档中发现,PS 日志记录模块正在执行我想要的操作。

Start Transcript 至少在我的情况下没有按预期工作。

谢谢。

祝你有愉快的一天。