共用方式為

Linter 规则 - 对部署脚本使用最新的 AZ PowerShell 版本

此规则检查低于 11.0 的 AZ PowerShell 版本。 建议使用 AZ PowerShell 版本 14.0。

Linter 规则代码

Bicep 配置文件 中使用以下值自定义规则设置:

use-recent-az-powershell-version

解决方案

以下示例不通过此测试, azPowerShellVersion 因为值为 10.4

param location string = resourceGroup().location
 
resource deploymentScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
  name: 'inlinePS'
  location: location
  kind: 'AzurePowerShell'
  properties: {
    azPowerShellVersion: '10.4'
    scriptContent: '''
      $output = 'Hello world!'
      $DeploymentScriptOutputs = @{}
      $DeploymentScriptOutputs['text'] = $output
    '''
    retentionInterval: 'PT1H'
  }
}
 
output result string = deploymentScript.properties.outputs.text

使用版本 11.0 或更高版本修复问题:

param location string = resourceGroup().location
 
resource deploymentScript 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
  name: 'inlinePS'
  location: location
  kind: 'AzurePowerShell'
  properties: {
    azPowerShellVersion: '14.0'
    scriptContent: '''
      $output = 'Hello world!'
      $DeploymentScriptOutputs = @{}
      $DeploymentScriptOutputs['text'] = $output
    '''
    retentionInterval: 'PT1H'
  }
}
 
output result string = deploymentScript.properties.outputs.text

后续步骤

“使用 Bicep linter”中了解详细信息。