【问题标题】:Change Azure Blob Storage Tier in Azure PowerShell Runbook在 Azure PowerShell Runbook 中更改 Azure Blob 存储层
【发布时间】:2019-09-16 10:08:20
【问题描述】:

我发现有几篇文章使用ICloudBlob.SetStandardBlobTier("Archive") 来更改CloudBlockBlob 的层级。因此,我将以下我想在 Azure PowerShell Runbook 中运行的脚本放在一起。

Import-Module Azure

#Define storage account information
$StorageAccount = "xxxxx"
$StorageAccountKey = "xxxxx"
$containername = "xxxxx"

#Create a storage context
$context = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey

# Get the blobs
$blobs = Get-AzureStorageBlob -Container $containername -Context $context
$blob = $blobs[0]

$blob.SetStandardBlobTier("Archive")

但这会产生以下错误消息

Method invocation failed because [Microsoft.WindowsAzure.Commands.Storage.Model.ResourceModel.AzureStorageBlob] does 
not contain a method named 'SetStandardBlobTier'.
At line:15 char:1
+ $blob.SetStandardBlobTier("Archive")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

当我调用Write-Output $blobs[0].ICloudBlob | Get-Member 时,我的对象似乎真的没有这样的方法:

[...]
RenewLease                    Method     void RenewLease(Microsoft.WindowsAzure.Storage.AccessCondition accessConditi...
RenewLeaseAsync               Method     System.Threading.Tasks.Task RenewLeaseAsync(Microsoft.WindowsAzure.Storage.A...
SetMetadata                   Method     void SetMetadata(Microsoft.WindowsAzure.Storage.AccessCondition accessCondit...
SetMetadataAsync              Method     System.Threading.Tasks.Task SetMetadataAsync(), System.Threading.Tasks.Task ...
SetProperties                 Method     void SetProperties(Microsoft.WindowsAzure.Storage.AccessCondition accessCond...
SetPropertiesAsync            Method     System.Threading.Tasks.Task SetPropertiesAsync(), System.Threading.Tasks.Tas...
Snapshot                      Method     Microsoft.WindowsAzure.Storage.Blob.CloudBlob Snapshot(System.Collections.Ge...
SnapshotAsync                 Method     System.Threading.Tasks.Task[Microsoft.WindowsAzure.Storage.Blob.CloudBlob] S...
StartCopy                     Method     string StartCopy(Microsoft.WindowsAzure.Storage.File.CloudFile source, Micro...
StartCopyAsync                Method     System.Threading.Tasks.Task[string] StartCopyAsync(Microsoft.WindowsAzure.St...
StartCopyFromBlob             Method     string StartCopyFromBlob(Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob ...
StartCopyFromBlobAsync        Method     System.Threading.Tasks.Task[string] StartCopyFromBlobAsync(Microsoft.Windows...
ToString                      Method     string ToString()                                                              
UploadFromByteArray           Method     void UploadFromByteArray(byte[] buffer, int index, int count, Microsoft.Wind...
[...]

我什至不知道如何从对象中读取当前层。我浏览了属性和元数据,但没有运气。

【问题讨论】:

    标签: azure powershell azure-blob-storage azure-runbook


    【解决方案1】:

    我可以重现您的问题,您使用的命令是旧的,请按照步骤解决问题。

    导航到您的 Runbook 所在的门户中的 automation account -> Modules -> 检查您是否有模块 Az.Accounts 1.6.2 和 Az.Storage 1.6.0,如果没有,请在 Browse Gallery 中搜索它们和Import(注意Az.Storage 1.6.0是Az.Storage的依赖,所以需要先导入Az.Accounts 1.6.2)。 如果您已经拥有旧版本,只需单击它们即可删除并导入上述最新版本。

    然后在你的运行手册中,使用如下命令,它在我这边工作正常。

    #Define storage account information
    $StorageAccount = "xxxxx"
    $StorageAccountKey = "xxxxx"
    $containername = "xxxxx"
    
    #Create a storage context
    $context = New-AzStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey
    
    # Get the blobs
    $blobs = Get-AzStorageBlob -Container $containername -Context $context
    $blob = $blobs[0]
    
    $blob.ICloudBlob.SetStandardBlobTier("Archive")
    

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 1970-01-01
      • 2017-06-14
      • 2021-12-12
      • 2018-06-16
      • 2021-10-30
      • 2019-03-20
      • 2018-12-17
      • 2013-12-11
      相关资源
      最近更新 更多