I have been ripping my hair out trying to get a CSV file that I am writing to a container to attach to an email I am sending. The file is being written to the container. I can see it. But the smtp.Attachments.Add() causes an error: “You cannot call a method on a null-valued expression.” This is the relevant code. What am I missing here?
$att = New-Item filename.csv -ItemType file
$DataSet.Tables | Export-CSV -NoTypeInformation $att
Set-AzureStorageBlobContent -File $att -Container $DestContainer -Context $StorageContext -Force
$blob = Get-AzureStorageBlob -Container $DestContainer -Context $StorageContext
$attachment = $blob.Name
$smtp.Send($From, $To, $subject, $body)