azure - Get-AzWebApp : The term 'Get-AzWebApp' is not recognized as the name of a cmdlet, 函数 - Azure Devops

标签 azure powershell azure-devops devops

我正在尝试通过 azure devops pipeline() 在 PowerShell 脚本下运行,以将新的专用终结点添加到我的 azure Vnet。不幸的是我遇到了以下错误。

错误:Get-AzWebApp:术语“Get-AzWebApp”未被识别为 cmdlet、函数、脚本文件或可操作的名称 程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试

azure-pipelines.yml

#Starter pipeline
#Start with a minimal pipeline that you can customize to build and deploy your code.
#Add steps that build, run tests, deploy, and more:
#https://aka.ms/yaml

trigger:
- main

pool:
  vmImage: 'windows-latest'

    steps:
    - task: AzureCLI@2
      inputs:
        azureSubscription: 'Azure subscription 1(XXXXXX)'
        scriptType: 'ps'
        scriptLocation: 'scriptPath'
        scriptPath: 'PrivateEndpointTest.ps1'

PrivateEndpointTest.ps1

$webapp = Get-AzWebApp -ResourceGroupName ENDPOINTTEST -Name anuendpointtest


## Create the private endpoint connection. ## 
$pec = @{
    Name = 'myConnection'
    PrivateLinkServiceId = $webapp.ID
    GroupID = 'sites'
}
$privateEndpointConnection = New-AzPrivateLinkServiceConnection @pec

## Place the virtual network you created previously into a variable. ##
$vnet = Get-AzVirtualNetwork -ResourceGroupName 'ENDPOINTTEST' -Name 'VNET_ENDPOINT_TEST'

## Create the private endpoint. ##
$pe = @{
    ResourceGroupName = 'VNET_ENDPOINT_TEST'
    Name = 'myPrivateEndpoint'
    Location = 'North Europe'
    Subnet = $vnet.Subnets[0]
    PrivateLinkServiceConnection = $privateEndpointConnection
}
New-AzPrivateEndpoint @pe

最佳答案

请尝试Azure PowerShell 任务并选择最新版本。

Azure CLI 需要以管理员身份运行以下命令:

Install-Module Az 

Import-Module Az 

如果要使用 Azure CLI,请考虑使用自托管代理。

Similar thread供您引用。

关于azure - Get-AzWebApp : The term 'Get-AzWebApp' is not recognized as the name of a cmdlet, 函数 - Azure Devops,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73880267/

相关文章:

Azure EventGrid 触发器 - Webhooks

powershell - 如何为 AutoIt 和 PowerShell 获得相同的 base64 编码?

session - 在不退出的情况下刷新/重新启动 PowerShell session

azure - 如何在 Azure DevOps Azure Powershell 任务中启用 PowerShell 交互模式?

azure-devops - Azure Devops Pipeline 中的作业完成后如何保护文件的安全?

azure - Azure 搜索成本取决于点击次数吗?

c# - 将网站发布到 Azure 云服务时,VS 2013 挂起

azure-devops - 如何让 Azure DevOps Pipeline 等待外部进程完成?

azure - 在 Windows Azure 媒体服务中上传和编码音频文件

powershell - 在 Powershell 中逐字符拆分字符串