powershell - 设置 ARM 模板 Web 应用程序设置

标签 powershell azure

如何使用 ARM 将应用程序设置部署到网站?

<小时/>

1 在 VS ARM Deploy json 中运行以下命令时:

....
     "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[variables('skuName')]",
        "capacity": "[variables('skuCapacity')]"
      },
      "properties": {
        "name": "[variables('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
        "displayName": "Website"
      },
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "web",
          "type": "config",
          "dependsOn": [
            "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
          ],
          "properties": {
            "netFrameworkVersion": "4.5.2",
            "use32BitWorkerProcess": true,
            "webSocketsEnabled": false,
            "alwaysOn": false,
            "requestTracingEnabled": true,
            "httpLoggingEnabled": true,
            "logsDirectorySizeLimit": 40,
            "detailedErrorLoggingEnabled": true,
            "appSettings": [
              {
                "name": "testn",
                "value": "testv"
              }
            ],
            "connectionstrings": [
              {
                "name": "testn",
                "value": "testv",
                "type": "SQLServer"
              }
            ]
          }
        }
      ]
    }
  ],

输出是;

VERBOSE: Performing the operation "Creating Deployment" on target "testdeploy3".
VERBOSE: 4:44:42 PM - Template is valid.
...
VERBOSE: 4:45:17 PM - Resource Microsoft.Web/sites/config 'testwebadtzmdritygpo/web' provisioning status is succeeded

...
ProvisioningState       : Succeeded

在门户中仔细检查显示应用程序设置和连接字符串尚未创建

问题 1:如何使用 PowerShell 查询网站的配置属性?

问题 2:如何使用 ARM 将应用程序设置部署到网站?

最佳答案

感谢@Alexander-s 和@davidebbo

使用 PowerShell

部署(无应用程序设置)成功后。然后运行它以完全覆盖应用程序设置。

$subscriptionID = {...}
Add-AzureRmAccount
Set-AzureRmContext -SubscriptionID $subscriptionID

# List appsettings
$resource = Invoke-AzureRmResourceAction -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName <webSiteName>/appsettings -Action list -ApiVersion 2015-08-01 -Force
$resource.Properties

# SET list
$appsettingTest1Value = "testValue1"
$appsettingTest2Value = "testValue2"
$PropertiesObject = @{
    appsettingTest1=$appsettingTest1Value,
    appsettingTest2=$appsettingTest2Value,
    WEBSITE_NODE_DEFAULT_VERSION: "4.4.7"
  }
New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName <webSiteName>/appsettings -ApiVersion 2015-08-01 -Force

使用 ARM 部署 JSON

{
  "apiVersion": "2015-08-01",
  "name": "[variables('webSiteName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[concat('Microsoft.Web/serverFarms/', parameters('hostingPlanName'))]",
    "[concat('Microsoft.Storage/storageAccounts/', variables('storage_account_name'))]",
    "[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]",
    "[resourceId('Microsoft.Sql/servers/databases', variables('sqlserverName'), parameters('database_name_auth'))]"
  ],
  "tags": {
    "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty",
    "displayName": "Website"
  },
  "properties": {
    "name": "[variables('webSiteName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "web",
      "type": "config",
      "dependsOn": [
        "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
      ],
      "properties": {
        "netFrameworkVersion": "[parameters('dotnet_version')",
        "use32BitWorkerProcess": "[parameters('use32bit_worker_process')",
        "webSocketsEnabled": false,
        "alwaysOn": "[parameters('enable_always_on')]",
        "requestTracingEnabled": true,
        "httpLoggingEnabled": true,
        "logsDirectorySizeLimit": 40,
        "detailedErrorLoggingEnabled": true
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
      ],
      "properties": {
        "appsettingTest1": "[parameters('appsettingTest1Value')]",
        "appsettingTest2": "[parameters('appsettingTest2Value')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "connectionstrings",
      "type": "config",
      "dependsOn": [
        "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
      ],
      "properties": {
        "dbconnstringTest1": {
          "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', parameters('database_name_auth'), ';User Id=', parameters('administratorLogin'), '@', variables('sqlserverName'), ';Password=', parameters('administratorLoginPassword'), ';')]",
          "type": "SQLServer"
        },
        "AzureWebJobsConnectionString": {
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storage_account_name'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storage_account_name')), '2015-05-01-preview').key1,';')]",
          "type": "Custom"
        }
      }
    }
  ]
},

关于powershell - 设置 ARM 模板 Web 应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40396154/

相关文章:

powershell - 如何从 PowerShell 中的 Windows 更新获取更新历史记录?

powershell - 你如何在powershell中解密securestring

azure - 如果我对 FileStream 的理解是正确的,则正确

Azure 自动缩放 - 我有哪些选项?

node.js - 用 Node.js 编写的 Azure Functions 可以访问连接字符串吗?

sharepoint - PowerShell STA模式是否可以消除SharePoint内存泄漏问题?

json - 如何从 Powershell 脚本读取 JSON 数据并遍历它

powershell - 如何在 PowerShell 中获取当前事件/前景窗口

azure - Web 部署到 Azure 失败 "Could not create SSL/TLS secure channel"

azure - Azure Kubernetes 服务中 PVC 的读写权限问题