gpt4 book ai didi

powershell - 通过电子邮件发送Powershell脚本的结果

转载 作者:行者123 更新时间:2023-12-03 01:00:41 25 4
gpt4 key购买 nike

运行以下脚本的结果将返回以下内容:

enter image description here

如何获得通过电子邮件发送的结果?我不确定如何将结果转换为可以传递给电子邮件脚本正文的参数:

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-6

$azPath = "C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy\"

Set-Location $azPath

$StorageAccountName = "#"

$StorageAccountKey = "#"

$ContainerName = "#"

$SourceFolder = "#"

$DestURL = "https://$StorageAccountName.blob.core.windows.net/$ContainerName"

$Result = .\AzCopy.exe /source:$SourceFolder /dest:$DestURL /BlobType:block /destkey:$StorageAccountKey /Y /S /XO

$Result

最佳答案

您可以将结果存储在文件中并作为附件发送:

$Result | Out-File Result.txt
Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>' -Subject 'Sending the Attachment' -Body "Forgot to send the attachment. Sending now." -Attachments .\Result.txt -SmtpServer 'smtp.fabrikam.com'

或将 $Result(= string [])的内容作为字符串发送到 -Body中:
$body = $Result -join '`n' # Join result to a single string with line breaks
Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>' -Subject 'Sending the Attachment' -Body $body -SmtpServer 'smtp.fabrikam.com'

或者(如@Olfa的评论所述)将其转换为HTML并添加 -BodyAsHtml开关:
$body = $Result | ConvertTo-Html
Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>' -Subject 'Sending the Attachment' -Body $body -SmtpServer 'smtp.fabrikam.com' -BodyAsHtml

关于powershell - 通过电子邮件发送Powershell脚本的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56821818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com