Attaching an Azure Blob to an email

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[0] | 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)


I’ve tried it this way as well…


$blob = Get-AzureStorageBlobContent -Container $DestContainer -Blob $att -Context $StorageContext
$attachment = $blob.Name
But this produces the following error:
Can not find blob 'C:\Temp\n3pwth0j.msw\filename.csv' in container 'ContainerName', or the blob type is unsupported.
It has to be one of these cmdlets right?