0

My powers-shell creates a output file which is

$csvpath = C:/temp/test.csv 
$FilePath = $CsvPath + $Compute.Name + "-" + (Get-Date).ToString("yyyyMMdd_HHmmss") + ".csv"
Export-Csv -InputObject $ComputeJobs -Path $FilePath

I want to automate this to run everyday, unfortunately I am not sure how to do it in Azure runbook.

requesting help to understand how to save files to azure storage using Azure Runbook.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
cloudcop
  • 957
  • 1
  • 9
  • 15

1 Answers1

0

They are two separated things. You're using Azure Automation to trigger the execution of your powershell script on predefined times. To save the output into Azure Storage, you actually needs the powershell code for it.

I'm not a powershell dev, but I assume the following should work:

Connect-AzAccount

# Define Variables
$subscriptionId = "yourSubscriptionId"
$storageAccountRG = "yourResourceGroup"
$storageAccountName = "yourStorageAccount"
$storageContainerName = "yourContainer"

# Select right Azure Subscription
Select-AzSubscription -SubscriptionId $SubscriptionId

# Get Storage Account Key
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccountRG -AccountName $storageAccountName).Value[0]

# Set AzStorageContext
$ctx = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

$csvpath = C:/temp/test.csv 
$FilePath = $CsvPath + $Compute.Name + "-" + (Get-Date).ToString("yyyyMMdd_HHmmss") + ".csv"
Export-Csv -InputObject $ComputeJobs | Set-AzureStorageBlobContent -Container $storageContainerName -Context $ctx 

https://learn.microsoft.com/en-us/powershell/module/azure.storage/set-azurestorageblobcontent?view=azurermps-6.13.0

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90