简体   繁体   中英

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

I am trying to run below PowerShell script via azure devops pipeline()to add a new Private endpoint to my azure .net. Unfortunately I'm getting below error.

Error: Get-AzWebApp: The term 'Get-AzWebApp' 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

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

Please try the Azure PowerShell task and select the latest version.

Azure CLI requires run command below as administrator:

Install-Module Az 

Import-Module Az 

If you want to use Azure CLI, consider using Self-host agent.

Similar thread for your reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM