Home > Enterprise >  Get-AzWebApp : The term 'Get-AzWebApp' is not recognized as the name of a cmdlet, function
Get-AzWebApp : The term 'Get-AzWebApp' is not recognized as the name of a cmdlet, function

Time:10-01

I am trying to run below PowerShell script via azure devops pipeline()to add a new Private endpoint to my azure Vnet. 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

CodePudding user response:

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.

  • Related