添加一个应用程序设置为使用现有的Azure电源外壳Azure的Web应用程序 [英] Adding an App Settings to existing Azure Web Application using Azure Power Shell

查看:102
本文介绍了添加一个应用程序设置为使用现有的Azure电源外壳Azure的Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写,采用蔚蓝色电源外壳来自动添加运行脚本的Web应用程序配置

天青> MyWebApp>应用程序设置>应用设置

这看起来像键=值

我写这个剧本

  ###########################
#MyApp的配置自动化#
############################开始$ subscriptionName =MySubscriptionName
$ webSiteName =MyWebAppName
$ storageAccountName =StorageAccountName
########################################
$ USERNAME =myaccount@outlook.com
$ securePassword =的ConvertTo-S​​ecureString的-STRING为mypass-AsPlainText -Force
#####################################
$ CRED =新对象System.Management.Automation.PSCredential($用户名,$ securePassword)
#####################################
附加AzureAccount -Credential $ CRED
选择-AzureSubscription -SubscriptionName $ subscriptionName - 默认
#####################################
GET-AzureWebsite -Name $ webSiteName#结束

但我知道,上面的脚本只是让我的Web应用程序,现在我需要访问MyWebApp>应用程序设置>应用程序设置,给我的新应用程序设置的脚本文件/阵列和脚本检查,如果有任何新应用程序设置键,将它添加到应用程序设置,如果有任何现有的按键,它会覆盖它的价值。
什么是步骤或API或我可以做到这一点与蔚蓝的电源外壳?

编辑:
该脚本可以自动创建新的Web应用程序,添加应用程序设置它:

  ###################################### ########
#创建网站和添加的Configs脚本#
##############################################$ webSiteName =mywebsite
$ storageAccountName =storageaccount
$ subscriptionName =mysubsc
$ USERNAME =我的帐户
$ securePassword =的ConvertTo-S​​ecureString的-STRING为mypass-AsPlainText -Force
$ CRED =新对象System.Management.Automation.PSCredential($用户名,$ securePassword)
附加AzureAccount -Credential $ CRED
选择-AzureSubscription -SubscriptionName $ subscriptionName - 默认新AzureWebsite -Name $ webSiteName
新AzureStorageAccount -StorageAccountName $ storageAccountName -Location南环美
$客户端Id =dfgdf6
$密码=ffefe
$ StorageAccountKey = GET-AzureStorageKey -StorageAccountName $ storageAccountName
$的AppSettings = @ {StorageAccountPrimary= $ StorageAccountKey.Primary;StorageAccountSecondary= $ StorageAccountKey.Secondary;IDA:客户端Id= $客户端Id;IDA:密码= $密码}设置AzureWebsite -Name $ webSiteName -AppSettings $的AppSettings


解决方案

检索应用程序设置

首先设置这两个变量。

  $ myResourceGroup ='RESOURCE_GROUP_NAME
$ MYSITE ='SITE_NAME

然后切换到新的资源管理模式,并登录到您的帐户。

 开关AzureMode AzureResourceManager
GET-AzureAccount

然后检索应用程序设置。 (注意,一个反勾号(`)表示新行)。

 (调用-AzureResourceAction -ResourceGroupName $ myResourceGroup`
 -ResourceType Microsoft.Web /网站/配置杂牌$ MYSITE /`的AppSettings
 清议名单-ApiVersion 2015年8月1日-Force)的.properties

添加/更新应用程序设置

要更新设置,首先把它们放到一个变量。

  $道具=(调用-AzureResourceAction -ResourceGroupName $ myResourceGroup`
 -ResourceType Microsoft.Web /网站/配置杂牌$ MYSITE /`的AppSettings
 清议名单-ApiVersion 2015年8月1日-Force)的.properties

要使用设置AzureWebsite 的变量转换为一个哈希表。

  $哈希= @ {}
 $道具|获得会员-MemberType NoteProperty | %{$哈希[$ _。名称] = $道具。($ _。名称)}

现在在哈希表中添加/更新值。

  $ hash.NewKey =的NewValue
$ hash.ExistingKey =的NewValue

再切换回服务管理模式,并提交设置。

 开关AzureMode AzureServiceManagement
设置AzureWebsite -Name $ MYSITE -AppSettings $哈希

完整code清单

  $ myResourceGroup ='RESOURCE_GROUP_NAME
$ MYSITE ='SITE_NAME开关,AzureMode AzureResourceManager
GET-AzureAccount(调用-AzureResourceAction -ResourceGroupName $ myResourceGroup`
 -ResourceType Microsoft.Web /网站/配置杂牌$ MYSITE /`的AppSettings
 清议名单-ApiVersion 2015年8月1日-Force)的.properties$道具=(调用-AzureResourceAction -ResourceGroupName $ myResourceGroup`
 -ResourceType Microsoft.Web /网站/配置杂牌$ MYSITE /`的AppSettings
 清议名单-ApiVersion 2015年8月1日-Force)的.properties $哈希= @ {}
 $道具|获得会员-MemberType NoteProperty | %{$哈希[$ _。名称] = $道具。($ _。名称)}$ hash.NewKey =的NewValue
$ hash.ExistingKey =的NewValue开关,AzureMode AzureServiceManagement
设置AzureWebsite -Name $ MYSITE -AppSettings $哈希

注释

该AzureServiceManagement和AzureResourceManager并不意味着在同一个会话使用。对于现在的后者似乎并没有允许通过更新应用程序设置设置-AzureResource 。以上是一个解决办法。另一种方式是使用天青CLI而不是PowerShell的

I want to write a script that run using azure power shell to automate adding the Web Application configuration

Azure > MyWebApp > Application Settings > App settings

It's look like key = "value"

I write this script

###########################
# MyApp Config Automation #
###########################

#Begin

$subscriptionName="MySubscriptionName"
$webSiteName="MyWebAppName"
$storageAccountName="StorageAccountName"
########################################
$userName = "myaccount@outlook.com"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
#####################################
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
#####################################
Add-AzureAccount -Credential $cred 
Select-AzureSubscription -SubscriptionName $subscriptionName -Default
#####################################
Get-AzureWebsite -Name $webSiteName

#End

but i know that the above script is only get my web application, now i need to access MyWebApp > Application Settings > App settings and give the script file/array of my new App settings and the script check if there are any new App Settings key it will add it to App Settings, if there are any existing keys it will override it's value. What is the steps or APIS or can i do that with azure power shell?

Edit: This script can Automate creating new web application and adding App Settings to it:

##############################################
# Creating website and Adding Configs Script #
##############################################

$webSiteName="mywebsite"
$storageAccountName="storageaccount"
$subscriptionName="mysubsc"
$userName = "myaccount"
$securePassword = ConvertTo-SecureString -String "mypass" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($userName, $securePassword)
Add-AzureAccount -Credential $cred 
Select-AzureSubscription -SubscriptionName $subscriptionName -Default

New-AzureWebsite -Name $webSiteName
New-AzureStorageAccount –StorageAccountName $storageAccountName -Location "South Central US"
$ClientId="dfgdf6"
$Password="ffefe"
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $storageAccountName
$AppSettings = @{"StorageAccountPrimary" = $StorageAccountKey.Primary;"StorageAccountSecondary" = $StorageAccountKey.Secondary;"ida:ClientId"=$ClientId;"ida:Password"=$Password}

Set-AzureWebsite -Name $webSiteName -AppSettings $AppSettings

解决方案

Retrieve App Settings

First set these two variables.

$myResourceGroup = 'RESOURCE_GROUP_NAME'
$mySite = 'SITE_NAME'

Then switch to the new Resource Manager mode and sign-in to your account.

Switch-AzureMode AzureResourceManager
Get-AzureAccount

Then retrieve the app settings. (Note that a back tick (`) means a new line.)

(Invoke-AzureResourceAction -ResourceGroupName $myResourceGroup `
 -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
 -Action list -ApiVersion 2015-08-01 -Force).Properties

Add/Update App Settings

To update settings, first put them into a variable.

$props = (Invoke-AzureResourceAction -ResourceGroupName $myResourceGroup `
 -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
 -Action list -ApiVersion 2015-08-01 -Force).Properties

To use Set-AzureWebsite convert the variable to a hash table.

 $hash = @{}
 $props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }

Now add/update values in the hash table.

$hash.NewKey = "NewValue"
$hash.ExistingKey = "NewValue"

Then switch back to Service Management mode and commit the settings.

Switch-AzureMode AzureServiceManagement
Set-AzureWebsite -Name $mySite -AppSettings $hash

Complete Code Listing

$myResourceGroup = 'RESOURCE_GROUP_NAME'
$mySite = 'SITE_NAME'

Switch-AzureMode AzureResourceManager
Get-AzureAccount

(Invoke-AzureResourceAction -ResourceGroupName $myResourceGroup `
 -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
 -Action list -ApiVersion 2015-08-01 -Force).Properties

$props = (Invoke-AzureResourceAction -ResourceGroupName $myResourceGroup `
 -ResourceType Microsoft.Web/sites/Config -Name $mySite/appsettings `
 -Action list -ApiVersion 2015-08-01 -Force).Properties

 $hash = @{}
 $props | Get-Member -MemberType NoteProperty | % { $hash[$_.Name] = $props.($_.Name) }

$hash.NewKey = "NewValue"
$hash.ExistingKey = "NewValue"

Switch-AzureMode AzureServiceManagement
Set-AzureWebsite -Name $mySite -AppSettings $hash

Notes

The AzureServiceManagement and AzureResourceManager are not meant for use in the same session. For now the latter does not seem to permit updating the app settings via Set-AzureResource. The above is a workaround. Another way is to use the Azure CLI instead of PowerShell.

这篇关于添加一个应用程序设置为使用现有的Azure电源外壳Azure的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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