I am trying to record my data to the Azure blob storage using the next command:
#Get PowerBI metrics
$Result = Get-PowerBIActivityEvent -StartDateTime 2023-03-13T23:58:59 -EndDateTime 2023-03-13T23:59:59
$Result = ($Result | ConvertFrom-Json) | Select-Object *
$Result = $Result | ConvertTo-Csv -NoTypeInformation
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
# Create a context object using Azure AD credentials
$ctx = New-AzStorageContext -StorageAccountName $accountName -UseConnectedAccount
$container = Get-AzStorageContainer -Name $containerName -Context $ctx
$date_loaded = (Get-Date -Format "MMddyyyy").ToString()
$content = [system.Text.Encoding]::UTF8.GetBytes($Result)
$container.CloudBlobContainer.GetBlockBlobReference($date_loaded+".csv").UploadFromByteArray($content,0,$content.Length)
The file is successfully created but all the records are in one line. I believe it's something with Encoding but I can't figure out how to fix it.
I know there is an option to record existing file to blob, but it doesn't work for me as I want to run it on cloud and I need direct conversion of the variable to the blob.