powershell - Azure Powershell 脚本忽略 defaultValue
问题描述
我正在使用 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"
},
参数.json:
"advisors_DropIndex_name": {
"value": null
},
该脚本返回以下内容:
新 AzureRmResourceGroupDeployment:下午 5:17:30 - 错误:代码 = 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
我究竟做错了什么 ?
解决方案
如果在部署期间没有提供值(例如 parameters.json),将使用defaultValue 。
在您的情况下,您提供的是该参数值,该参数值为null,并且每个错误消息都无效(例如 InvalidDeploymentParameterValue)。
如果要应用默认值,请从 parameters.json 文件中删除整个以下代码。
"advisors_DropIndex_name": {
"value": null
},
在https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-parameters查找更多详细信息。
推荐阅读
- excel - VBA 在 Word Doc 中选择范围,然后在 Excel 中粘贴范围
- java - 为什么我收到警告消息“从 /Names 字典中删除 /IDTree,不属于那里”?
- android - Android:示例数据表示不是字符串
- ruby-on-rails - 如何使用 ActiveStorage 和 AWS Rails 6 创建图像的永久链接
- python-3.x - 如何识别正在使用的 geckodriver.exe?
- python - Python web 抓取 span id 使用 Beautiful soup
- javafx - 如何判断颜色是否为绿色?
- angular - 延迟加载组件时Angular 11不是已知的子元素
- flutter - 如何在 Flutter 中相对于另一个小部件定位小部件?
- javascript - 每次打开时自动关闭弹出窗口(jquery/javascript)