0
votes

I found several articles that use ICloudBlob.SetStandardBlobTier("Archive") to change the tier of a CloudBlockBlob. So I put together the following script that I want to run in an 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")

But this produces the following error message

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

When I call Write-Output $blobs[0].ICloudBlob | Get-Member it seems my object really has no such method:

[...]
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...
[...]

I don't even know how to read the current tier from the object. I went through the properties and metadata, but no luck.

1

1 Answers

2
votes

I can reproduce your issue, the command you are using is old, follow the steps to fix the issue.

Navigate to the automation account in the portal which your runbook located -> Modules -> check if you have the modules Az.Accounts 1.6.2 and Az.Storage 1.6.0, if not, in the Browse Gallery -> search for them and Import(note the Az.Storage 1.6.0 is a dependency of Az.Storage, so you need to import Az.Accounts 1.6.2 first). If you already had the old version of them, just click them to delete and import the latest version like above.

Then in your runbook, use the command as below, it works fine on my side.

#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")