azure - 在 Azure PowerShell Runbook 中更改 Azure Blob 存储层

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

我发现有几篇文章使用 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...
[...]

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

最佳答案

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

导航到 Runbook 所在门户中的自动化帐户 -> 模块 -> 检查是否有模块 Az.Accounts 1.6.2Az.Storage 1.6.0,如果没有,请在 浏览库 -> 中搜索它们并导入(请注意 Az.Storage 1.6.0Az.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")

关于azure - 在 Azure PowerShell Runbook 中更改 Azure Blob 存储层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57929145/

相关文章:

TFS/Azure Devops 使用的 Powershell 子表达式语法

Powershell:删除所有包含字符串的注册表项

azure - 将 Blob 存储挂载为 VM 上的驱动器

azure - 设置 Azure 存储容器的默认缓存 header

testing - TRX 记录器在 Azure 角色上不可用

azure - 我可以使用 Windows 镜像作为 Azure WebRole 的 guest 操作系统吗?

c# - 允许用户进行表单例份验证在 Azure 网站中不起作用

powershell - 为什么当我在 PowerShell 中通过引用传递此属性时未更新它

c# - 如何从 MemoryStream 重新创建 Zip 文件

azure - Azure 应用服务中的 Swagger 身份验证