Temp location to download blob and update the blob using runbook and powershell

Azure-learning 56 Reputation points
2022-09-14T18:11:08.673+00:00

Temporary location to save the log file using automation runbook and update blob using powershell.

I am getting error- " Can not find the specified file 'C:\Windows\System32\log.txt'.

I am using below code - I am running in it automationrunbook.

  someoutput | Out-File -FilePath "$env:temp\log.txt"  -Append  

tried with : Set-AzStorageBlobContent -Container  "data1" -File "log.txt" -Blob "log.txt" -Context $context -Force   

tried with : Set-AzStorageBlobContent -Container "data1" -File "$env:temp\log.txt" -Blob "log.txt" -Context $context -Force

I am getting error in both the cases. it's not updating blob file .please suggest . there is some issue with "file" parameter .i need to use some temp location .

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

2 answers

Sort by: Most helpful
  1. Maxim Sergeev 6,586 Reputation points Microsoft Employee
    2022-09-15T00:41:02.863+00:00

    Hi there,

    Use a temporary folder like $env:TEMP first.
    https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution#temporary-storage-in-a-sandbox

    The example below

    $File=$env:TEMP + "\yourfile.txt"  
    Get-AzureStorageFileContent -Path $File  
    Get-Content $File  
    
    0 comments No comments

  2. Limitless Technology 44,751 Reputation points
    2022-09-19T08:59:34.397+00:00

    Hi NGaur,

    Thank you for posting your query.

    I have found an article with the same issue that you are encountering check this link https://learn.microsoft.com/en-us/answers/questions/408295/how-do-i-download-blob-file-from-an-azure-blob-sto.html

    $resourceGroup = "myRG"
    $storageAccountName = "AccountName"
    $containerName = "listtestblobs"

    $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup
    -Name $storageAccountName
    $ctx = $storageAccount.Context

    Get-AzStorageBlobContent -Blob "Image001.jpg" -Container $containerName
    -Destination "D:_TestImages\Downloads\" `
    -Context $ctx

    Go to this link for your referencehttps://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-powershell


    If the answer is helpful kindly click "Accept as Answer" and upvote it. Thanks.

    0 comments No comments

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.