Should files are uploaded or downloaded from an Azure Storage Account Blob, there are corresponding PowerShell commands. Specifically, Get-AzStorageBlobContent or Set-AzStorageBlobContent can be used. Both commands always require the specification of a local file.

In some cases, however, it may be necessary to edit the file content without having to work with a local file. The ICloudBlob interface can be used for this, which provides the functions UploadText and DownloadText.

The following script copies the empty template.txt file in the testcontainer container and assigns the name newfile.txt. This is done in lines 9 and 10. Since no new file can be created with the ICloudBlob functions, an empty file (template.txt) must be created in the storage account first, which is then copied. Afterwards, the newly created file is retrieved in line 11 and line 12 finally sets the new file content and line 13 shows the retrieval of the file content.

$StrgAccountName = "..."
$StrgAccountKey = "..."
$StrgContainer = "testcontainer"
$templatefile = "template.txt"
$blobname = "newfile.txt"
$filecontent = "this is example content`r`nof a new file`r`nstored in azure"

$ctx = New-AzStorageContext -StorageAccountName $StrgAccountName -StorageAccountKey $StrgAccountKey
$templateBlob = Get-AzStorageBlob -Context $ctx -Container $StrgContainer -Blob $templatefile
$templateBlob | Start-AzStorageBlobCopy -Context $ctx -DestContext $ctx -DestContainer $StrgContainer -DestBlob $blobname
$newBlob = Get-AzStorageBlob -Context $ctx -Container $StrgContainer -Blob $blobname
$newBlob.ICloudBlob.UploadText($filecontent)
$newBlob.ICloudBlob.DownloadText()