getting this error - An error occurred in Initialize-AzModule
##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
##[error]PowerShell exited with code '1'.
In this yml stage -
## Edge-Test-LAXr9a HC - Alert on Failure (Non-Release Stage)
- stage: "Edge_Test_LAXr9a_HC_Alert"
displayName: "LAXr9a Alert on Failure"
dependsOn: Test_Edge_LAXr9a_HealthCheck
condition: failed()
jobs:
- job: Send_Alert_To_Log_Analytics
displayName: "Send Alert To Log Analytics"
pool:
type: windows
variables:
ob_outputDirectory: '$(Build.SourcesDirectory)\out'
steps:
- task: AzurePowerShell@5
displayName: "Azure PowerShell script: Create Alert If Pipeline Fails"
inputs:
azureSubscription: "AFD-MSFT-Ops: Infrastructure Services"
ScriptType: 'InlineScript'
azurePowerShellVersion: 'OtherVersion'
preferredAzurePowerShellVersion: '9.7.1'
Inline: |
# PowerShell script to send alert to Log Analytics
# Az.Accounts is already available in AzurePowerShell task
# Define Key Vault and secrets
$KeyVaultName = "Pipeline-LAWSecret"
$LogAnalyticsWorkspaceIdSecretName = "LogAnalyticsWorkspaceID"
$LogAnalyticsSharedKeySecretName = "LogAnalyticsSharedKey"
# Retrieve secrets from Azure Key Vault
try {
$LogAnalyticsWorkspaceId = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $LogAnalyticsWorkspaceIdSecretName -AsPlainText
$SharedKey = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $LogAnalyticsSharedKeySecretName -AsPlainText
Write-Host "Successfully retrieved Log Analytics Workspace ID and Shared Key."
} catch {
Write-Host "Failed to retrieve secrets from Key Vault: $_"
exit 1
}
...
...