I want to send an email from my powershell runbook script, I wouild like to attach CSV file as the script output which is stored in storage blob on my azure subscription.
The script is ready, I am receiving email but without attachment. I am still facing the issue, and when I am executing script from Azure automation, as a runbook, I can see below error message. I am storing all files in the same container.
New-Object : Exception calling ".ctor" with "1" argument(s): "Could not find file 'C:\Users\Client\Temp\xxxxxxxx.csv'."
this is my output --> $ArrayStatus | Export-Csv -NoTypeInformation -Path "$filename"
$filename is a CSV file location
$ArrayStatus | Export-Csv -NoTypeInformation -Path "$filename"
Get-AzureStorageBlob -Container "xxx" -Blob "$filename" -Context $Context
Get-AzureStorageBlobContent -force
$attachment = "$filename"
Function Email ($EmailTo, $Body){
$EmailFrom = "xxx"
$Subject = "xxx Alert"
$SMTPServer = "xxx"
$SMTPMessage = New-Object
System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$attach = New-Object System.Net.Mail.Attachment($attachment)
$SMTPMessage.Attachments.Add($attach)
$SMTPMessage.IsBodyHTML = $false
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, xx)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("xx",
"xx");
$SMTPClient.Send($SMTPMessage)
}
I am receiving email but without CSV file attachment