我正在尝试为更改Azure存储Blob层创建Azure自动化,但它无法正常工作。 [英] I am trying to create Azure Automation for Change Azure Storage Blob Tiers but it is not working.

查看:95
本文介绍了我正在尝试为更改Azure存储Blob层创建Azure自动化,但它无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Support,


我正在尝试为更改Azure存储Blob层创建Azure自动化,但无法在下面的脚本中填充我的参数,但它在我的环境中不起作用 



<预类= "x_x_powershell" 风格= ""> <跨度类= "x_x_powerShell__keyword" 样式="颜色:#006699;字体 - 重量:粗体 "> PARAM (&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP; [参数(强制性= <跨度类=" x_x_powerShell__variable"样式= "颜色:#aa7700"> $真< /跨度>)]鸟;&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP; [字符串]鸟<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ AzureSubscriptionID &NBSP; =&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝"> [使用&NBSP; *默认&NBSP;天青&NBSP;认购*&NBSP;变量&NBSP;值" ,&NBSP;&NBSP;
&NBSP; &NBSP;&NBSP;&NBSP; [参数(强制性= <跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $真)]鸟;&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP ; [String]  $ StorageAccountName   =  " mystorageaccountname" ,  
     [参数(强制= $ true )]  
     [String]  $ StorageTier   =  " Hot  /  Cool  /  Archive" ,  
     [参数(强制= $ true )]  
     [int] $ DaysOld   
) 
 
     $ ServicePrincipalConnection   = 获取 - AutomationConnection&NBSP; <跨度类=" x_x_powerShell__operator"样式= "颜色:灰色"> - 名称&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝">" AzureRunAsConnection'&NBSP;
 
     $ null   = 添加 - AzureRmAccount&NBSP;`&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - ServicePrincipal&NBSP;`&NBSP;
         - TenantId  $ ServicePrincipalConnection .TenantId&NBSP;`&NBSP;
         - ApplicationId  $ ServicePrincipalConnection .ApplicationId&NBSP;`&NBSP;
         - CertificateThumbprint  $ ServicePrincipalConnection .CertificateThumbprint&NBSP;
 
     # 选择  Azure 订阅 
&NBSP;&NBSP;&NBSP;&NBSP;写<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 输出&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝"> "选择&NBSP;天青&NBSP;订阅..." &NBSP;
     $ Subscription   = 获取 - AzureRmSubscription  - SubscriptionId  $ AzureSubscriptionID   - TenantId  $ ServicePrincipalConnection .TenantId&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP; <跨度类= "x_x_powerShell__alias" 样式= "颜色:#006699;字型重量:大胆">选择 <跨度类= "x_x_powerShell__operator" 样式="颜色:grey"> -
AzureRmSubscription  - 订阅  $订阅&NBSP;
 
# 设置 存储 连接   
<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ StgAcct &NBSP; =&NBSP;获得<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> -
AzureRmStorageAccount  |  
其中<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 对象&NBSP; {(<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ _ .StorageAccountName  - eq  $ StorageAccountName )  ; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> -
和&NBSP;(<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ _ .sku.tier&NBSP ; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 当量&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝"> '标准')&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> -
和&NBSP;(<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ _ .Kind&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 当量&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝"> 'StorageV2'&NBSP; <跨度类=" x_x_powerShell__operator"style ="color:gray"> -
或  $ _ .Kind  - eq  'BlobStorage')} 
 
写<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 输出&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝">"存储&NBSP;帐户&NBSP;名称&NBSP;是:&NBSP; $($ StgAcct.StorageAccountName)" &NBSP;
 
<跨度类= "x_x_powerShell__keyword" 样式= "颜色:#006699;字型重量:粗体">如果&NBSP;(<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ StgAcct )&NBSP; {&NBSP;
 
$ StgAcctKey   = (获取 - AzureRmStorageAccountKey  - ResourceGroupName ( $ StgAcct ).ResourceGroupName&NBSP;`&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < span class ="x_x_powerShell__operator"style ="color:grey"> -
名称 ( $ StgAcct )。StorageAccountName).Value [0]鸟
 
$ StgAcctContext   = 新 - AzureStorageContext  - StorageAccountName ( $ StgAcct ) .StorageAccountName&NBSP;`&NBSP;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;                     - StorageAccountKey  $ StgAcctKey  
<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $ StorageContainers &NBSP; =&NBSP;获得<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> -
AzureStorageContainer  - 上下文  $ StgAcctContext  
 
<跨度类= "x_x_powerShell__com" 样式= "颜色:绿">#&NBSP;循环&NBSP;通过&NBSP;全部共个斑点&NBSP;在&NBSP;所述&NBSP;存储&NBSP;帐户&NBSP;
$ Blobs   =  @() 
foreach $ StorageContainer &NBSP; <跨度类= "x_x_powerShell__keyword" 样式= "颜色:#006699;字型重量:粗体">中&NBSP; <跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700" > $ StorageContainers ){&NBSP;
<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $斑点&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> + =&NBSP ;获取<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - AzureStorageBlob&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 上下文&NBSP; <跨度类= "x_x_powerShell__variable"style ="color:#aa7700"> $ StgAcctContext
  - Container ( $ StorageContainer )名称&NBSP;

 
# 日期 逻辑 
$ UTCDate   = (获取-日期)ToUniversalTime()&NBSP;
$ RetentionDate   =  $ UTCDate .AddDays( - $ DaysOld )  ;
$ EarmarkedBlobs   =  $ Blobs < /跨度>&NBSP; <跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> | &NBSP;其中<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 对象&NBSP; { $ _ .lastmodified.DateTime  - le  $ RetentionDate
 
# 更改     blob      
<跨度类= "x_x_powerShell__keyword" 样式= "颜色:#006699;字型重量:粗体"> FOREACH (<跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700"> $斑点&NBSP; <跨度类= "x_x_powerShell__keyword" 样式= "颜色:#006699;字型重量:粗体">中&NBSP; <跨度类= "x_x_powerShell__variable" 样式= "颜色:#aa7700" > $ EarmarkedBlobs ){&NBSP;
#设置所有  blob 以及所需的 层  
$ blob .icloudblob.SetStandardBlobTier( $ StorageTier < /跨度>)&NBSP;

 
写<跨度类= "x_x_powerShell__operator" 样式= "颜色:灰色"> - 输出&NBSP; <跨度类= "x_x_powerShell__string" 样式= "颜色:蓝">"`n`nDone .. &NBSP;完成&NBSP;检查&NBSP;您的&NBSP;博客&NBSP;层级&NBSP;在&NBSP;所述&NBSP; portal.`n" &NBSP;
 
else   { 
 
<跨度类= "x_x_powerShell__cmdlets" 样式= "颜色:#006699;字型重量:粗体">写错误&NBSP;"你&NBSP;选择&NBSP;存储&NBSP;帐户&NBSP;不能&NBSP;被&NBSP;使用,&NBSP;&最NBSP;&可能NBSP;&因为NBSP;这是&NBSP;`&NBSP;
不&NBSP; A&NBSP; V2&NBSP;存储和NBSP;账户,&NBSP; A&NBSP; BLOB&NBSP;存储&NBSP;帐户&NBSP;或&NBSP;这是&NBSP;不&NBSP; A&NBSP;标准&NBSP;存储和NBSP;帐户];&NBSP;
 
}


解决方案

您好PK_TECHNET,


想知道您要更改哪个Blog级别?热/冷/存档?


我建议尝试以下方法查看是否有效。例如。如果您要设置为存档。使用如下内容:


   [String] 


StorageTier   =  " Archive"


如果您还没有看到这个,请参阅
类似的MSDN帖子
作为指导 - 相关答案剪下面。



Hi Support,

I am trying to create Azure Automation for Change Azure Storage Blob Tiers but unable to fill my parameters in below script and it is not working in my environment. 

param( 
    [parameter(Mandatory=$true)]  
    [String] $AzureSubscriptionID = "Use *Default Azure Subscription* Variable Value",  
    [parameter(Mandatory=$true)]  
    [String] $StorageAccountName = "mystorageaccountname",  
    [parameter(Mandatory=$true)]  
    [String] $StorageTier = "Hot / Cool / Archive",  
    [parameter(Mandatory=$true)]  
    [int]$DaysOld  
) 
 
    $ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection' 
 
    $null = Add-AzureRmAccount ` 
        -ServicePrincipal ` 
        -TenantId $ServicePrincipalConnection.TenantId ` 
        -ApplicationId $ServicePrincipalConnection.ApplicationId ` 
        -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint 
 
    # Select Azure Subscription 
    Write-Output "Select Azure subscription…" 
    $Subscription = Get-AzureRmSubscription -SubscriptionId $AzureSubscriptionID -TenantId $ServicePrincipalConnection.TenantId 
    Select-AzureRmSubscription -Subscription $Subscription 
 
# Setup the Storage Connection stuff 
$StgAcct = Get-AzureRmStorageAccount | 
Where-Object {($_.StorageAccountName -eq $StorageAccountName-and ($_.sku.tier -eq 'Standard'-and ($_.Kind -eq 'StorageV2' -or $_.Kind -eq 'BlobStorage')} 
 
write-output "Storage Account Name is: $($StgAcct.StorageAccountName)" 
 
if ($StgAcct) { 
 
$StgAcctKey = (Get-AzureRmStorageAccountKey -ResourceGroupName ($StgAcct).ResourceGroupName ` 
                                            -Name ($StgAcct).StorageAccountName).Value[0] 
 
$StgAcctContext = New-AzureStorageContext -StorageAccountName ($StgAcct).StorageAccountName ` 
                                          -StorageAccountKey $StgAcctKey 
$StorageContainers = Get-AzureStorageContainer -Context $StgAcctContext 
 
# Cycle through all blobs in the storage account 
$Blobs = @() 
foreach($StorageContainer in $StorageContainers){ 
$Blobs += Get-AzureStorageBlob -Context $StgAcctContext -Container ($StorageContainer).Name 
} 
 
# Date Logic 
$UTCDate = (Get-Date).ToUniversalTime() 
$RetentionDate = $UTCDate.AddDays(-$DaysOld$EarmarkedBlobs = $Blobs | Where-Object {$_.lastmodified.DateTime -le $RetentionDate} 
 
# Change the Tier on the blobs 
Foreach($Blob in $EarmarkedBlobs){ 
#Set tier of all blobs to desired tier 
$blob.icloudblob.SetStandardBlobTier($StorageTier) 
} 
 
Write-Output "`n`nDone... Complete. Check your Blog Tiers in the portal.`n" 
 
} else { 
 
Write-Error "Your selected Storage account cannot be used, most likely because it's ` 
not a V2 Storage account, a blob storage account or it's not a Standard Storage account" 
 
}

解决方案

Hi PK_TECHNET,

Curious to know which Blog Tier you are trying to change to? Hot/Cold/Archive?

I suggest trying the below to see if it works. eg. if you are trying to set to Archive. use something like:

  [String] 


StorageTier = "Archive"

If you haven't seen this already, refer to this similar MSDN post for guidance - relevant answer snipped below.


这篇关于我正在尝试为更改Azure存储Blob层创建Azure自动化,但它无法正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆