0

我正在尋找一種方式來實現在做一個藍色的自動化密鑰輪換我已經找到一種方法來創建一個PowerShell的運行手冊,並已實現了以下代碼:Azure的旋轉存儲密鑰和更新ADF鏈接服務

$azureAccountName = <acct_name> 
$azurePassword = ConvertTo-SecureString <pass> -AsPlainText -Force 
$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword) 
Login-AzureRmAccount -ServicePrincipal -Credential $psCred -TenantId <tenant id> -SubscriptionId <sub id> 

#Optionally you may set the following as parameters 
$StorageAccountName = <storage acct name> 
$RGName = <rg name> 

#Key name. For example key1 or key2 for the storage account 
New-AzureRmStorageAccountKey -ResourceGroupName $RGName -Name $StorageAccountName -KeyName "key1" -Verbose 
New-AzureRmStorageAccountKey -ResourceGroupName $RGName -Name $StorageAccountName -KeyName "key2" -Verbose 

當我運行這個,它工作,但是,它打破了我的Azure數據工廠鏈接服務。我意識到鏈接服務的連接字符串被破壞,所以我着手嘗試重置自動化腳本中的連接字符串。我能夠做得到連接字符串:

(Get-AzureRmDataFactoryLinkedService -DataFactoryName <adf name> -ResourceGroupName <rg name> -Name <ls name>).Properties.TypeProperties.ConnectionString 

我不能找到一種方法來設置使用PowerShell和蔚藍的自動化此連接字符串。

回答

1

您可以使用Power Shell來休息此連接。但您需要使用Remove-AzureRmDataFactoryLinkedService(從Azure Data Factory中刪除鏈接的服務),並使用New-AzureRmDataFactoryLinkedService將您的存儲帳戶重新鏈接到數據工廠。

請參考此tutorial

你需要創建一個JSON文件象下面這樣:

{ 
    "name": "AzureStorageLinkedService", 
    "properties": { 
     "type": "AzureStorage", 
     "typeProperties": { 
      "connectionString": "DefaultEndpointsProtocol=https;AccountName=<accountname>;AccountKey=<accountkey>" 
     } 
    } 
} 

使用New-AzureRmDataFactoryLinkedService鏈接。

New-AzureRmDataFactoryLinkedService -ResourceGroupName ADFTutorialResourceGroup -DataFactoryName <Name of your data factory> -File .\AzureStorageLinkedService.json 

但是,如果您使用Azure自動執行此操作,則會遇到一個問題。在runbook中,你不能存儲json文件,也許你可以保存在公共github上(不安全)。另一種解決方案是使用Hybrid Runbook Worker

+0

我們仍在研究此解決方案並將其作爲Hybrid Runbook Worker運行。謝謝你的回答! –