0

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
anuruddhas
  • 55
  • 5
  • Will the answer above solve your issue? https://stackoverflow.com/questions/57055269/azure-devops-powershell-get-azsubscription-is-not-recognized – Andriy Bilous Sep 28 '22 at 11:38

1 Answers1

1

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.

Minxin Yu - MSFT
  • 2,234
  • 1
  • 3
  • 14