在运行以下脚本的结果中,它返回以下内容:

如何通过电子邮件发送此结果?我不确定如何将结果放入可以传递到电子邮件脚本正文的参数中:
$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发布于 2019-06-30 14:23:22
您可以将结果存储在文件中,并将其作为附件发送:
$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'或者在-Body中将$Result (=string[])的内容作为字符串发送:
$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' -BodyAsHtmlhttps://stackoverflow.com/questions/56821818
复制相似问题