Search code examples
azurepowershellazure-blob-storageazure-automationazure-runbook

How to access local file path in Azure power shell Run book


Team, I am trying to upload a file from local machine to azure blob storage account. I am able to upload file by running script in local power shell. However when i tried same script in Azure Automation Power shell runbook I am getting error.

Test-Path -Path 'D:\UploadFolder\Sample.txt' -- Returns True in local powershell while uploading
Test-Path -Path 'D:\UploadFolder\Sample.txt' -- Returns False in azure automation powershell runbook while uploading

Error: Drive 'D' not found

I checked below code in Runbook which return false.

Get-PSDrive -Name 'D' -- Return false

My Questions:

1) How we can access any local file path in runbook ?

2) Do we have any blade in azure to store/create files in Automation Account itself?. (Purpose of this asking is "I Would like to create file in azure automation manually/script wise to write some content in to it and later to upload same file in Azure blob storage.)

Thanks in advance


Solution

  • You cannot access your local system file through Azure Automation. If you have small information like key-value, you store in Azure Automation variable section

    //Get variable value in Automation PowerShell script

    $cosmosDbAccountName = Get-AutomationVariable -Name 'CosmosDbAccountName'
    $databaseName = Get-AutomationVariable -Name 'DatabaseName'
    

    Option 1

    You can upload your file in blob and read a blob from Azure Automation Script.

    Option 2

    You can use WebJob (App Service) to run PowerShell script and you can upload both script and file in WebJob.