Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Principal login with domain name results in 'Invalid GUID' errors for subsequent cmdlets #6709

Closed
markcowl opened this issue Jul 20, 2018 · 2 comments
Assignees
Milestone

Comments

@markcowl
Copy link
Member

Here is an example:

PS C:\Users\markcowl> Connect-AzureRmAccount -TenantId mydomainname.onmschina.cn -Environment AzureChinaCloud -Credential $cred -ServicePrincipal


Account          : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
SubscriptionName : Azure SDK Mooncake Powershell Test
SubscriptionId   : yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
TenantId         : mydomainname.onmschina.cn
Environment      : AzureChinaCloud


PS C:\Users\markcowl> Select-AzureRmSubscription -Subscription yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
Select-AzureRmSubscription : Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
At line:1 char:1
+ Select-AzureRmSubscription -Subscription 5c9daa8a-5529-41e1-81c6-549a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmContext], FormatException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand

PS C:\Users\markcowl>

This occurs because the cmdlet is trying to retrive a tenant id from the domain name when constructing a tenant object:

PS C:\Users\markcowl> Resolve-AzureRmError -Last


   HistoryId: 15


Message        : Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
StackTrace     :    at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object
                 failureMessageFormatArgument, String failureArgumentName, Exception innerException)
                    at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
                    at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
                    at System.Guid..ctor(String g)
                    at
                 Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureTenantExtensions.GetId(IAzureTenant
                 tenant)
                    at Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.<>c__DisplayClass45_0.<TryF
                 indContext>b__0(KeyValuePair`2 c)
                    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
                    at
                 Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.TryFindContext(IAzureContext
                 context, String& name)
                    at Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.TrySetDefaultContext(IAzure
                 Context context)
                    at
                 Microsoft.Azure.Commands.Common.Authentication.Models.AzureRmProfile.TrySetDefaultContext(String
                 name, IAzureContext context)
                    at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.SetCurrentContext(String
                 subscriptionNameOrId, String tenantId, String name)
                    at Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand.<>c__DisplayClass37_1.<ExecuteCmdlet>b
                 __2(AzureRmProfile profile, RMProfileClient client, String name)
                    at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2
                 contextAction)
                    at
                 Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand.SetContextWithOverwritePrompt(Action`3
                 setContextAction)
                    at Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : System.FormatException
InvocationInfo : {Set-AzureRmContext}
Line           : Select-AzureRmSubscription -Subscription 5c9daa8a-5529-41e1-81c6-549ad83077df
Position       : At line:1 char:1
                 + Select-AzureRmSubscription -Subscription 5c9daa8a-5529-41e1-81c6-549a ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 15
@markcowl
Copy link
Member Author

The proper thing in this case is to perform the extra hop to extract the tenant id, and ensure this is saved in the tenant id property in the context.

@markcowl markcowl changed the title Service Principal login with domain name results in 'Invlaid GUID' errors fpr subsequent cmdlets Service Principal login with domain name results in 'Invalid GUID' errors forsubsequent cmdlets Jul 21, 2018
@markcowl markcowl changed the title Service Principal login with domain name results in 'Invalid GUID' errors forsubsequent cmdlets Service Principal login with domain name results in 'Invalid GUID' errors for subsequent cmdlets Jul 21, 2018
@markcowl markcowl added this to the 2018-08-10 milestone Jul 31, 2018
@cormacpayne
Copy link
Member

This has been fixed and will be available in version 6.7.0 of AzureRM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants