azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Login-AzureRmAccount not working with org id credentials from get-credentials

Open theMichaelB opened this issue 11 years ago • 9 comments

When running Login-AzureRmAccount and interactively logging in with an organisational ID, it works as expected and gives a list of subscriptions from Get-AzureRmSubscription

Whereas this doesn't work

$Credential = Get-Credential Add-AzureRmAccount -Credential $Credential

At this point, it does provide Account, TenantId and SubscriptionId as expected, however

When I subsequently run Get-AzureRmSubscription I get -

Get-AzureRmSubscription : Could not authenticate with tenant . Please ensure that your account has access to this tenant and log in with Login-AzureRmAccount

theMichaelB avatar Nov 07 '15 10:11 theMichaelB

@Cloudry Is this a csp account? In the CSP account scenario, you must provide -TenantId when listing subscriptions

markcowl avatar Nov 09 '15 17:11 markcowl

@markcowl What is a CSP account? I'm not immediately familiar with this acronym. Is the "SP" for "Service Principal?" If so, what is the "C" for, then?

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

pcgeek86 avatar Nov 09 '15 20:11 pcgeek86

CSP = Cloud Solution Provider.

ciphertxt avatar Nov 09 '15 20:11 ciphertxt

It is an MSDN account with multiple subscriptions under the same tenant, but providing the -TenantId does seem to work.

I have been trying to load up multiple accounts, but RM only appears to support having a single account loaded at a time (In classic mode I could Add-AzureAccount both my prod and dev tenants and simply Select-AzureSubscription amongst them.

If I was able to load multiple tenants specifying the tenant id would make sense (even then, classic mode could work around it), but since it only allows one to load at a time...

theMichaelB avatar Nov 10 '15 02:11 theMichaelB

@Cloudry The issue shouldonly occur if the credentials you provided cannot be authenticated against the common tenant. If you use credentials that have access to multiple tenants, all tenants you have access to will be used when listing subscriptions. BTW, there is a work item in the current sprint to make specifying the -TenantId unnecessary in this scenari. You can follow the story here: https://www.pivotaltracker.com/story/show/107740454

As to multiple accounts, It is a different model, and I expect it will take some time to get used to if you have been using the older model. Users were often confused by having multiple active logins, and the local cache of subscriptions is much more likely to get quickly out of date in AzureRm. You can still easily switch between logins using something like:

$profile1 = Login-AzureRmAccount 
$profile2 = Login-AzureRmAccount

Select-AzureRmProfile -Profile $profile2

You can also save profiles to disk using

Save-AzureRMProfile

markcowl avatar Nov 11 '15 01:11 markcowl

Thank you @markcowl that does cover the issues I have been having.

(though I would add that the documentation for Login-AzureRmAccount / Select-AzureRmProfile really doesn't put across what it does, or how to use it! - Where are the help files located? I suppose the whole point of it being here is that we can fix stuff ourselves! I'm a little out of my depth with the C# stuff, but I'm sure I can hack some help text)

theMichaelB avatar Nov 12 '15 23:11 theMichaelB

I have been struggling with EXACTLY the same problem.

"When running Login-AzureRmAccount and interactively logging in with an organisational ID, it works as expected and gives a list of subscriptions from Get-AzureRmSubscription

Whereas this doesn't work

$Credential = Get-Credential Add-AzureRmAccount -Credential $Credential

At this point, it does provide Account, TenantId and SubscriptionId as expected, however

When I subsequently run Get-AzureRmSubscription I get -

Get-AzureRmSubscription : Could not authenticate with tenant . Please ensure that your account has access to this tenant and log in with Login-AzureRmAccount"

However, I tried the -Tenantid with the get-Azurermsubscription and in my case I get the same error. I am using an AD organizational account.

Any ideas what might be "special" about me ?

BradHudon avatar Dec 10 '15 02:12 BradHudon

Forget it . I just figured out what's special about me and you don't wanna know .

BradHudon avatar Dec 10 '15 02:12 BradHudon

@BradHudon what was your issue - I'm struggling in the same way as you?

Moffmo avatar Jan 20 '16 05:01 Moffmo