Azure Powershell脚本忽略了defaultValue

时间:2018-06-28 21:24:02

标签: powershell azure azure-resource-manager azure-deployment

我正在使用PowerShell ISE通过Azure门户中为该资源生成的脚本来重新创建现有数据库。我发现PS不使用脚本路径,因此在顶部添加了以下几行:

Write-Host $PSScriptRoot
Push-Location $PSScriptRoot
Write-Host "Path: $(get-location)"

我添加了一些测试代码,以确保template.json和parameters.json存在并且可以正常工作:

# Start the deployment
Write-Host "Starting deployment...";
Write-Host "Testing: $templateFilePath"
if(Test-Path $templateFilePath) {
    Write-Host "FOUND: $templateFilePath"

    if(Test-Path $parametersFilePath) {
        Write-Host "FOUND: $parametersFilePath"
        New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath;
    } else {
        New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath;
    }

}

但是,脚本仍然忽略template.json中的defaultValue参数:

"advisors_DropIndex_name": {
    "defaultValue": "DropIndex",
    "type": "String"
},

parameters.json:

"advisors_DropIndex_name": {
    "value": null
},

脚本返回以下内容:

New-AzureRmResourceGroupDeployment:5:17:30 PM-错误:代码= InvalidDeploymentParameterValue; Message =部署参数“ keys_ServiceManaged_name ”的值为空。请明确说明 值或使用参数引用。有关详情,请参见https://aka.ms/arm-deploy/#parameter-file。 在C:\ Users \ longoj \ Downloads \ ExportedTemplate-DEEAResourceGroup \ deploy.ps1:110 char:9 + New-AzureRmResourceGroupDeployment -ResourceGroupName $ resour ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~     + CategoryInfo:未指定:(:) [New-AzureRmResourceGroupDeployment],异常     + FullyQualifiedErrorId:Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

如果在parameters.json中设置值:

"advisors_DropIndex_name": {
    "value": "DropIndex"
},

脚本验证移至下一个参数,并且有很多参数。因此,看起来template.json文件的defaultvalue参数被忽略了。

我正在使用:

Version           : 5.1.2
Name              : Azure
Author            : Microsoft Corporation
PowerShellVersion : 3.0

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

如果在部署过程中未提供任何值(例如parameters.json),则将使用 defaultValue

在您的情况下,您要提供的参数值为,并且对于每个错误消息均无效(例如InvalidDeploymentParameterValue)。

如果要应用默认值,请从parameters.json文件中删除以下整个代码。

"advisors_DropIndex_name": {
    "value": null
},

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-parameters上找到更多详细信息。

相关问题