重命名具有特定条件的天蓝色斑点

问题描述 投票:-1回答:2

我有一个带有Test容器的存储帐户,该容器包含24个文件夹,每个文件夹包含n个Blob。我想要的是将Pic 1中的所有文件夹和子Blob重命名为与Pic 2中的完全相同。

enter image description hereenter image description here

我使用了以下重命名脚本:How to rename a blob file using powershell

但是上面的脚本对于一个或两个Blob有用,而且此脚本不会重命名文件夹(可以通过将Blob复制到新位置来解决),在我的情况下,我有n Blob,我试图用:

$textinfo = (Get-Culture).TextInfo
$text2=($textinfo.ToTitleCase($text)).Split(" ")

但是这也无济于事,因为它将exchangerate重命名为Exchangerate,而不是ExchangeRate(这是实际要求)。我想到了:

foreach($file in $text)
    {
        Get-AzStorageBlob -Container 'test' -Context $storageContext -Blob $text|
        Rename-AzStorageBlob -NewName ''
    }

但是新名称(参数)无法动态显示。如何处理?

azure azure-storage-blobs
2个回答
2
投票

如果要将Blob从exchangerate重命名为ExchangeRate,则没有自动方法。

为此,正如Martin所提到的,最好有一个映射,您可以在其中查找exchangerate-> ExchangeRate(并且对于所有其他名称,都包含多个单词)。

否则,您的代码将不知道新Blob名称中的字母是否应大写。


0
投票

修改了我的代码,如下所示

##Lookup.
$hash = $null
##Hash table with keys in Lowercase and values in Uppercase
$hash = @{...}

##Renaming the files.
$file = $null
$file1 = $null
foreach($file in $text)
    {
       if($hash.Values -eq $file)
            { 
                Write-Host 'Old name' $file
                foreach($file1 in $hash.Values)
                    {
                        if($file -eq $file1)
                            {
                                Write-Host 'New name' $file1
                                Get-AzStorageBlob -Container 'test' -Context $storageContext -Blob $file| Rename-AzStorageBlob -NewName $file1 
                            }
                    }
            }      

    }

所以这对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.