Is there a way to rename the case sensitivity for multiple files on blob storage RRS feed

  • Question

  • Hi,

    I have a big web application with huge amount of files on Azure Blob Storage to be used through CDN. is there any way to  change all files to lower case, what are the options to do that?

    Tuesday, October 9, 2018 9:20 AM

All replies

  • a quick hack in PowerShell seems to work for my test. Example below. No doubt there are other ways.

    Import-Module AzureRM.Storage
    function Set-CaseOnBlobsInStorageAccount  {
      PARAM (
        [Parameter(Mandatory = $true)] [ValidateSet('ToUpper','ToLower')] [string]$case,
        [Parameter(Mandatory = $true)] [string]$ResourceGroupName,
        [Parameter(Mandatory = $true)] [string]$StorageAccountName
      Add-Type -AssemblyName Microsoft.WindowsAzure.Storage
      $StorageAccountName = $StorageAccountName.ToLower()
      if (Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -EA SilentlyContinue)  {
        $StorageAccountKeys    = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName
        $StorageAccountKey     = $StorageAccountKeys[0].Value
        $StorageAccountContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
        $StorageContainers     = Get-AzureStorageContainer -Context $StorageAccountContext
        #retrive all blobs from containers
        $Blobs = @()
        foreach($StorageContainer in $StorageContainers){
          $Blobs += Get-AzureStorageBlob -Context $StorageAccountContext -Container $StorageContainer.Name
        Foreach($srcBlob in $Blobs) {
          Write-Verbose -Message ('checking {0}' -f  $srcBlob.ICloudBlob.Uri.AbsoluteUri)
          switch ($case) {
            'ToUpper' {$newName = $OldName.ToUpper()}
            'ToLower' {$newName = $OldName.ToLower()}
           #if it needs a rename, copy the file to the new name, then delete the old one...
          if ($newName -cne $OldName) {
            $destBlob = $srcBlob.ICloudBlob.Container.GetBlockBlobReference($newName)
      else {
        Write-Error -Message ('StorageAccount {0} was not found' -f $StorageAccountName)
    Set-CaseOnBlobsInStorageAccount -case ToUpper -ResourceGroupName testRG -StorageAccountName testofcasestorage

    Thursday, October 11, 2018 3:28 AM