运行以下脚本的结果是,它返回以下内容:
如何通过电子邮件发送此结果?我不确定如何将结果转换为可以传递给电子邮件脚本正文的参数:
$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
答案 0 :(得分:3)
您可以将结果存储在文件中并作为附件发送:
$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