Search code examples
powershellazure-devopsansibleazure-dashboard

The term New-AzPortalDashboard is not recognized as a name in a azure pipeline


In summary I am ask to add an Azure Dashboard via an ansible playbook. I always get the error "The term New-AzPortalDashboard is not recognized as a name"

There is a pipeline file that

In the playbook it's basically doing stuff with an api and "include_tasks" an yml file. This yml file call a ps1 file to create stuff.

In that ps1 file I added a function to get the format of a azure dashboard do some update and call the New-AzPortalDashboard.

function Add-Dashboard {
param ([String]$subscriptionID,[String]$resourceGroup,[String]$apiManagementName,[String]$dashboardTitle,[String]$location)

$file = New-TemporaryFile

$Content = Get-Content ./templates/api-management-dashboard.json  
$Content = $Content -replace '<subscriptionID>', $subscriptionID
$Content = $Content -replace '<ressourceGroupName>', $resourceGroup
$Content = $Content -replace '<apiManagementName>', $apiManagementName
$Content = $Content -replace '<dashboardTitle>', $dashboardTitle
$Content = $Content -replace '<location>', $location
$Content | Set-Content $file

$DashboardParams = @{
  DashboardPath = $file
  ResourceGroupName = $resourceGroup
  DashboardName = $dashboardTitle
}
New-AzPortalDashboard @DashboardParams

Remove-Item -Path $file
}

I try to Install-Module for "Az", "Az.Portal" and "Az.Ressource" in the pipeline and the ps1 but it did not work.


Solution

  • Did you check the solution here: Azure DevOps CI/CD missing command: New-AzPortalDashboard

    Additionally, verify you are using pwsh core on your build agent:

    for classic:

    enter image description here

    for yaml:

    - task: PowerShell@2
      inputs:
        targetType: filePath
        filePath: .....
        pwsh: true