I have a PowerShell file which is use for getting the secret value from one of our Azure Key Vault for later use (login to Power BI with Service Principal). Here is the screenshot from DevOps,
And here is my PS code,
Write-Output "Get Secret from AKV"
$secret = az keyvault secret show --vault-name PA01 --name <my key vault secret name> --output json
$x = $secret | ConvertFrom-Json
$azureAplicationId = "<my client id>"
$azureTenantId= "<my tenant id>"
Write-Output "Generate Credential"
$azurePassword = ConvertTo-SecureString $x.value -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Write-Output "Login SP"
Connect-PowerBIServiceAccount -Tenant $azureTenantId -ServicePrincipal -Credential $psCred
I can run it successfully on Cloud shell, while it fails on my Azure DevOps pipeline. As you can see the screenshot below,
I think the job failed when running this command:
$secret = az keyvault secret show --vault-name PA01 --name <my key vault secret name> --output json
Because although the job has automatic running the Connect-AzAccount command, the login is invalid, and on my understand that is why it say "Error: Please run az login to setup account" (guess so), so the "az keyvault" command cannot be run.
Yes, I can add "az login --use-device-code" on my script and it run successful by enter code manually, but the problem is,
I don't want any interactive experience in the login process, because I hope this job is fully automatic and unattended.
So, any solution for this? Deeply grateful for you help!

