是否可以使用Azure Powershell更新Azure Cloud Service中設置的值?如何使用Azure Powershell更新Azure Cloud Service設置
3
A
回答
5
到目前爲止,沒有辦法更新只有一個設置(服務管理API不允許它 - 它只接受整個服務配置)。所以,爲了更新一個設置,你將不得不更新整個配置。你可以使用PowerShell做到這一點:
# Add the Azure Account first - this will create a login promppt
Add-AzureAccount
# when you have more then one subscription - you have explicitly select the one
# which holds your cloud service you want to update
Select-AzureSubscription "<Subscription name with spaces goes here>"
# then Update the configuration for the cloud service
Set-AzureDeployment -Config -ServiceName "<cloud_service_name_goes_here>" `
-Configuration "D:/tmp/cloud/ServiceConfiguration.Cloud.cscfg" `
-Slot "Production"
爲我提供新的配置文件,我想用我的雲服務使用完整的本地路徑的`構成 - 」參數。
這是驗證和工作的解決方案。
3
正如astaykov所說,您無法使用Powershell更新單個雲配置值。
但你可以閱讀所有的設置,更新你想改變,它保存到臨時文件,然後重新設置所有的設置,像這樣的一個:
UpdateCloudConfig.ps1:
param
(
[string] $cloudService,
[string] $publishSettings,
[string] $subscription,
[string] $role,
[string] $setting,
[string] $value
)
# param checking code removed for brevity
Import-AzurePublishSettingsFile $publishSettings -ErrorAction Stop | Out-Null
function SaveNewSettingInXmlFile($cloudService, [xml]$configuration, $setting, [string]$value)
{
# get the <Role name="Customer.Api"> or <Role name="Customer.NewsletterSubscription.Api"> or <Role name="Identity.Web"> element
$roleElement = $configuration.ServiceConfiguration.Role | ? { $_.name -eq $role }
if (-not($roleElement))
{
Throw "Could not find role $role in existing cloud config"
}
# get the existing AzureServiceBusQueueConfig.ConnectionString element
$settingElement = $roleElement.ConfigurationSettings.Setting | ? { $_.name -eq $setting }
if (-not($settingElement))
{
Throw "Could not find existing element in cloud config with name $setting"
}
if ($settingElement.value -eq $value)
{
Write-Host "No change detected, so will not update cloud config"
return $null
}
# update the value
$settingElement.value = $value
# write configuration out to a file
$filename = $cloudService + ".cscfg"
$configuration.Save("$pwd\$filename")
return $filename
}
Write-Host "Updating setting for $cloudService" -ForegroundColor Green
Select-AzureSubscription -SubscriptionName $subscription -ErrorAction Stop
# get the current settings from Azure
$deployment = Get-AzureDeployment $cloudService -ErrorAction Stop
# save settings with new value to a .cscfg file
$filename = SaveNewSettingInXmlFile $cloudService $deployment.Configuration $setting $value
if (-not($filename)) # there was no change to the cloud config so we can exit nicely
{
return
}
# change the settings in Azure
Set-AzureDeployment -Config -ServiceName $cloudService -Configuration "$pwd\$filename" -Slot Production
# clean up - delete .cscfg file
Remove-Item ("$pwd\$filename")
Write-Host "done"
相關問題
- 1. Azure Cloud Service - settings.setting
- 2. 如何在端點配置更改時升級Azure Cloud Service?
- 3. Azure Cloud Service PHP梨包
- 4. 如何在不使用Sql Azure數據庫的情況下運行Azure Cloud Service?
- 5. 沒有端點的Azure ReservedIPAddress&Cloud Service
- 6. 下載Windows Azure Cloud Service的vhd
- 7. 如何使用Azure Powershell SDK爲Azure Web應用程序設置Java/Tomcat選項
- 8. Azure Cloud Service - 創建項目需要安裝Microsoft Azure Tools v2.5
- 9. 以編程方式修改Azure Cloud Service配置?
- 10. 我可以在Azure App Service上運行Node/ExpressJS應用程序還是必須使用Azure Cloud Service?
- 11. 使用實體框架從Cloud Service連接到Azure數據庫
- 12. 針對多個SSL證書的Azure Cloud Service配置
- 13. 使用Azure CLI設置Azure網站AlwaysOn
- 14. 如何獲取Azure Cloud Service的SSL證書
- 15. 如何合理將具有長初始化的Azure Cloud Service轉換爲Azure Service Fabric服務?
- 16. 如何在Azure Service Fabric無狀態Web API中設置網頁?
- 17. Azure Cloud服務
- 18. Azure Powershell設置Cors允許起源
- 19. 使用Azure PowerShell添加或更新(Set)端點
- 20. 如何強制Powershell使用新的Azure訂閱
- 21. 將MVC應用程序遷移到AZure Appservice和Cloud Service
- 22. 如何通過Powershell配置新的Azure AD應用程序?
- 23. 如何設置Azure Connect?
- 24. 使用Powershell更改Windows更新設置
- 25. Azure App Service Mobile + Web
- 26. 如何在Azure自動化操作手冊中使用Service Fabric Powershell cmdlet
- 27. 使用PowerShell創建Azure Flask
- 28. 使用PowerShell和FTP創建Azure網站
- 29. Azure Cloud中的MongoDB
- 30. 使用Lucene.Net和Azure App Service無法訪問Azure存儲