azure - 无法识别“New-AzSqlServerFirewallRule” - Azure Dev Ops Pipeline 的 Azure PowerShell 问题

标签 azure powershell

我正在尝试使用自动部署中的管道运行 SQL 脚本,以使用以下 YML 文件进行数据库更改。但我收到以下错误消息。

我遵循的教程是:https://learn.microsoft.com/en-us/azure/devops/pipelines/targets/azure-sqldb?view=azure-devops&tabs=yaml

trigger:
 - main

pool:
  vmImage: windows-2022

variables:
  AzureSubscription: 'XXX'
  ResourceGroupName: 'XXX'
  ResourceDBGroupName: 'XXX'
  ServerName: 'XXX'
  DatabaseName: 'XXX'
  AdminUser: 'XXX'
  AdminPassword: 'XXX'
  SQLFile: 'DatabasePipelineTest/scripts/script.sql'
  AzureFirewallName: 'allow-pipe'

steps:
- script: dir
  displayName: 'Run a one-line script to test'

- task: AzurePowerShell@2
  displayName: Azure PowerShell
  inputs:
    azureSubscription: '$(AzureSubscription)'
    ScriptPath: '$(Build.SourcesDirectory)/DatabasePipelineTest/scripts/SetAzureFirewallRule.ps1'
    ScriptArguments: '-ServerName $(ServerName) -ResourceGroupName $(ResourceDBGroupName) -AzureFirewallName $(AzureFirewallName)'
    azurePowerShellVersion: LatestVersion

- task: CmdLine@1
  displayName: Run Sqlcmd
  inputs:
    filename: Sqlcmd
    arguments: '-S $(ServerName) -U $(AdminUser) -P $(AdminPassword) -d $(DatabaseName) -i $(SQLFile)'

- task: AzurePowerShell@5
  displayName: Azure PowerShell
  inputs:
    azureSubscription: '$(AzureSubscription)'
    ScriptPath: '$(Build.SourcesDirectory)/DatabasePipelineTest/scripts/RemoveAzureFirewallRule.ps1'
    ScriptArguments: '$(ServerName)'
    azurePowerShellVersion: LatestVersion

我在控制台中得到的输出如下,

Azure PowerShell

View raw log
Starting: Azure PowerShell
==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 2.198.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-powershell
==============================================================================
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\azurerm_6.13.1\AzureRM\6.13.1\AzureRM.psd1 -Global
Clear-AzureRmContext -Scope Process
Disable-AzureRmContextAutosave -ErrorAction Stop
Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
Clear-AzureRmContext -Scope Process -ErrorAction Stop
##[error]The term 'New-AzSqlServerFirewallRule' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Finishing: Azure PowerShell

有问题的脚本如下

[CmdletBinding(DefaultParameterSetName = 'None')]
param
(
  [String] [Parameter(Mandatory = $true)] $ServerName,
  [String] [Parameter(Mandatory = $true)] $ResourceGroupName,
  [String] [Parameter(Mandatory = $true)] $AzureFirewallName
)
$agentIP = (New-Object net.webclient).downloadstring("https://api.ipify.org")
New-AzSqlServerFirewallRule -ResourceGroupName $ResourceGroupName -ServerName $ServerName -FirewallRuleName $AzureFirewallName -StartIPAddress $agentIp -EndIPAddress $agentIP

最佳答案

如果您指定了任务版本,是否可以 checkin DevOps 任务:4。 (预览) 或更高版本以使用 Az powershell 模块

关于azure - 无法识别“New-AzSqlServerFirewallRule” - Azure Dev Ops Pipeline 的 Azure PowerShell 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71446862/

相关文章:

azure - PowerShell 列出所有 Azure VM 数据磁盘大小困惑

azure - Service Fabric 可靠参与者和 I/O 操作

windows - PowerShell:查询 2008 服务器的页面文件信息

.net - 在 Powershell v3 中无需调用外部 EXE 即可确定 .NET 程序集是否为混合模式

python - 在一个位置为多个站点更新 azure token ,无需域访问

azure - 上传的证书在多个 Azure Web 应用程序中可见

azure - 使用 ServiceBusMessageBatch 和在 TransactionScope 中发送多条消息有什么区别?

powershell - 此计算机上未安装 WAPPSCmdlet

rest - 是否有适用于 Azure 应用服务的 REST API

wpf - Powershell 数据模板绑定(bind)语法