Append when using temp storage in Azure Automation

Peter Svensson 211 Reputation points
2023-10-24T07:40:30.8933333+00:00

I have a Azure Automation runbook that gathers cost information and saves in it a blob storage. It uses the temporare storage temp ($env:temp) before it saves it to the blob storage.
https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution

My problem is that it doesn't seem to work to append to the temp storage file. I have several runbooks that need to append to a cvs file (not at the same time) but I cant get it to work. Is this a limitation with the temp storage?

My runbook below

get-azsubscription | Export-Csv -path $env:TEMP\cost.csv -NoTypeInformation -Append

$file = get-item -path $env:TEMP\cost.csv


Set-AzContext -Subscription "xxxxxxxx"
$Context = New-AzStorageContext -StorageAccountName "storageaccount" -UseConnectedAccount
Set-AzStorageBlobContent -Context $Context -Container "costfiles" -File $file.FullName -Blob "cost.csv" -Force
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,426 Reputation points Moderator
    2023-10-30T03:59:33.5733333+00:00

    Hi @Peter Svensson ,

    When you say that you can't get it to work, are you seeing any error?

    With regards to limitation with temp storage, as explained here, the only limitation is you can't use more than 1 GB of disk space, which is the quota for each sandbox.

    As explained here, Azure Automation assigns a worker to run each job during runbook execution in the sandbox. While workers are shared by many Automation accounts, jobs from different Automation accounts are isolated from one another so, I believe few of your runbook execution's isolation might be the reason for you to not able to append content to your intended csv file.

    So, to try resolving the issue in this case, write your runbooks in such a way that you append the content from each runbook execution to the csv file that's stored in blob storage.

    Example:

    Runbook 1 -> $env:TEMP\xxx.csv -> cost.csv in blob storage

    Runbook 2 -> $env:TEMP\yyy.csv -> cost.csv in blob storage

    Runbook 3 -> $env:TEMP\zzz.csv -> cost.csv in blob storage


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.