Service Principal az cli login failing - NO subscriptions found Service Principal az cli login failing - NO subscriptions found powershell powershell

Service Principal az cli login failing - NO subscriptions found


Actually, I don't recommend you to mix the Azure Powershell and CLI together. If you insist on doing it, I have tried your script, I could not reproduce your issue, it works fine. According to the error, you could try to pass a --subscription, it also works.

$sp_appid = (Get-AzADServicePrincipal -DisplayName joywebapp2).ApplicationId.Guid$sp_secret = (Get-AzKeyVaultSecret -VaultName joykeyvault1 -Name joywebapp2).SecretValueText$tenant_Id = "xxxxxxxxxxxx"$subscription_Id = "xxxxxxxxxxx"az login --service-principal --username $sp_appid --password $sp_secret --tenant $tenant_Id --subscription $subscription_Id

enter image description here

Note: Due to the AzureRM powershell module has been deprecated, I use the new Az powershell module, if you want to upgrade to Az, see this link. (It may not be the reason of the issue, but I recommend you to upgrade it.)

Update:

We have to use AZ CLI simply for the property we are trying to grab...there is no PowerShell equivalent.

Actually you can login with a service principal via powershell, the strong password is the secret, more details see this post.

$azureAplicationId ="Azure AD Application Id"$azureTenantId= "Your Tenant Id"$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)Add-AzureRmAccount -Credential $psCred -TenantId $azureTenantId  -ServicePrincipal


The original problem appears to have been a transient platform problem. Went back to the same code yesterday and it work with no issues.


I had the same issue that suddenly no subscriptions where showing up for my service principal (on 2 different build servers that I originally installed at the same time).

Updating the Azure CLI seemed to fix the issue.