'Powershell to upload text string to blob through Azure Automation account
There is no local machine to store a intermittent file. Read data from Blob to string variable, after modification of text string, need to upload the content to destination azure blob through azure automation account using powershell. Everything need to be done in Azure automation account.
Solution 1:[1]
Read data from Blob to string variable
If it is the big blob, then Output the blob content to a stream else Output the blob content as string.
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName
$Blob = Get-AzureStorageBlob -Context $StorageAccount.Context -Container $container -Blob $Filename
$Text = $blob.ICloudBlob.DownloadText()
Write-Output $Text
To get the contents of the blob as a string and pipe it to convertfrom-json directly:
$blobs | Get-AzureStorageBlobContent -AsString | ConvertFrom-Json ...
There are different download options available for Text, Byte, File and Stream in ($Blob.ICloudBlob | Get-Member | where {$_.Name -like "Download*"} | select Name) gives you:
DownloadBlockList
DownloadBlockListAsync
DownloadRangeToByteArray
DownloadRangeToByteArrayAsync
DownloadRangeToStream
DownloadRangeToStreamAsync
DownloadText
DownloadTextAsync
DownloadToByteArray
DownloadToByteArrayAsync
DownloadToFile
DownloadToFileAsync
DownloadToStream
DownloadToStreamAsync
After modification of blob content, for uploading the modified content to the destination blob with the help of Azure Automation and PowerShell commands, please refer the below references will helps you for the following above:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HariKrishnaRajoli-MT |
