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

Select-AzureRMSubscription does not change the subscription from the default #6289

Closed
dufc1923 opened this issue May 24, 2018 · 22 comments
Closed

Comments

@dufc1923
Copy link

Description

i set $subscriptionid to a specific subscription that exists..
but when I exectute Select-AzureRmSubscription -SubscriptionId $subscriptionid it doesnt set me to be using that subscription and I am left in my default subscription..

I've been using the command succesfully for months..
and even yesterday I used it about 3 or 4 times and it worked, then all of a sudden it stopped working..

Script/Steps for Reproduction

image

Select-AzureRmSubscription -SubscriptionId $subscriptionid

Module Version

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Script 5.0.1 AzureRM.profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}
Script 0.6.5 AzureRM.ServiceBus {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace, Set-AzureRmServiceBusNamespace, Remove-AzureRmServiceBusNamespace...}

Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager

ModuleType Version Name ExportedCommands


Script 0.6.3 AzureRM.AnalysisServices {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnalysisServicesServer, Get-AzureRmAnalysisServicesServer, Remove-AzureRmAnalysisServicesServer...}
Script 5.1.0 AzureRM.ApiManagement {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoToken, New-AzureRmApiManagementHostnameConfiguration, New-AzureRmApiManagementRegion...}
Script 0.1.1 AzureRM.ApplicationInsights {Get-AzureRmApplicationInsights, New-AzureRmApplicationInsights, Remove-AzureRmApplicationInsights, Set-AzureRmApplicationInsightsPricingPlan...}
Script 4.2.1 AzureRM.Automation {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutomationJobOutputRecord, Import-AzureRmAutomationDscNodeConfiguration, Export-AzureRmAutomationDscConfiguration...}
Script 4.0.2 AzureRM.Backup {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerReregistration, Get-AzureRmBackupContainer, Register-AzureRmBackupContainer...}
Script 4.0.4 AzureRM.Batch {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-AzureRmBatchAccountKeys, New-AzureRmBatchAccount...}
Script 0.14.0 AzureRM.Billing {Get-AzureRmBillingInvoice, Get-AzureRmBillingPeriod}
Script 4.1.0 AzureRM.Cdn {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureRmCdnProfile, Remove-AzureRmCdnProfile...}
Script 0.9.1 AzureRM.CognitiveServices {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServicesAccountKey, Get-AzureRmCognitiveServicesAccountSkus, New-AzureRmCognitiveServicesAccount...}
Script 4.3.2 AzureRM.Compute {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New-AzureRmAvailabilitySet, Update-AzureRmAvailabilitySet...}
Script 0.3.0 AzureRM.Consumption Get-AzureRmConsumptionUsageDetail
Script 0.2.3 AzureRM.ContainerInstance {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-AzureRmContainerGroup, Get-AzureRmContainerInstanceLog}
Script 1.0.2 AzureRM.ContainerRegistry {New-AzureRmContainerRegistry, Get-AzureRmContainerRegistry, Update-AzureRmContainerRegistry, Remove-AzureRmContainerRegistry...}
Script 4.1.0 AzureRM.DataFactories {Remove-AzureRmDataFactory, Get-AzureRmDataFactoryRun, Get-AzureRmDataFactorySlice, Save-AzureRmDataFactoryLog...}
Script 0.5.0 AzureRM.DataFactoryV2 {Set-AzureRmDataFactoryV2, Update-AzureRmDataFactoryV2, Get-AzureRmDataFactoryV2, Remove-AzureRmDataFactoryV2...}
Script 4.2.1 AzureRM.DataLakeAnalytics {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogSecret...}
Script 5.1.1 AzureRM.DataLakeStore {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreFirewallRule, Set-AzureRmDataLakeStoreTrustedIdProvider...}
Script 0.1.0 AzureRM.DataMigration {New-AzureRmDataMigrationDatabaseInfo, New-AzureRmDataMigrationConnectionInfo, New-AzureRmDataMigrationProject, Remove-AzureRmDataMigrationProject...}
Script 4.0.2 AzureRM.DevTestLabs {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShutdownPolicy, Get-AzureRmDtlAutoStartPolicy, Get-AzureRmDtlVMsPerLabPolicy...}
Script 4.0.1 AzureRM.Dns {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-AzureRmDnsRecordSet, Set-AzureRmDnsRecordSet...}
Script 0.3.1 AzureRM.EventGrid {New-AzureRmEventGridTopic, Get-AzureRmEventGridTopic, Set-AzureRmEventGridTopic, New-AzureRmEventGridTopicKey...}
Script 0.6.1 AzureRM.EventHub {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Set-AzureRmEventHubNamespace, Remove-AzureRmEventHubNamespace...}
Script 4.0.2 AzureRM.HDInsight {Get-AzureRmHDInsightJob, New-AzureRmHDInsightSqoopJobDefinition, Wait-AzureRmHDInsightJob, New-AzureRmHDInsightStreamingMapReduceJobDefinition...}
Script 4.0.2 AzureRM.Insights {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRmLogProfile, Get-AzureRmLogProfile...}
Script 3.1.0 AzureRM.IotHub {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGroup, Get-AzureRmIotHubConnectionString, Get-AzureRmIotHubJob...}
Script 4.1.1 AzureRM.KeyVault {Add-AzureKeyVaultCertificate, Set-AzureKeyVaultCertificateAttribute, Stop-AzureKeyVaultCertificateOperation, Get-AzureKeyVaultCertificateOperation...}
Script 4.0.1 AzureRM.LogicApp {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegrationAccountCallbackUrl, Get-AzureRmIntegrationAccountCertificate, Get-AzureRmIntegrationAccount...}
Script 0.17.0 AzureRM.MachineLearning {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentPlanUsageHistory, Remove-AzureRmMlCommitmentPlan...}
Script 0.4.0 AzureRM.MachineLearningCompute {Get-AzureRmMlOpCluster, Get-AzureRmMlOpClusterKey, Test-AzureRmMlOpClusterSystemServicesUpdateAvailability, Update-AzureRmMlOpClusterSystemService...}
Script 0.2.0 AzureRM.MarketplaceOrdering {Get-AzureRmMarketplaceTerms, Set-AzureRmMarketplaceTerms}
Script 0.9.0 AzureRM.Media {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServiceKey, Get-AzureRmMediaServiceKeys, Get-AzureRmMediaServiceNameAvailability...}
Script 5.2.0 AzureRM.Network {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-AzureRmApplicationGatewayAuthenticationCertificate, New-AzureRmApplicationGatewayAuthenticationCertificate, Remove-AzureRmApplicationGatewayAuthenti...
Script 4.1.0 AzureRM.NotificationHubs {Get-AzureRmNotificationHub, Get-AzureRmNotificationHubAuthorizationRules, Get-AzureRmNotificationHubListKeys, Get-AzureRmNotificationHubPNSCredentials...}
Script 4.2.0 AzureRM.OperationalInsights {New-AzureRmOperationalInsightsAzureActivityLogDataSource, New-AzureRmOperationalInsightsCustomLogDataSource, Disable-AzureRmOperationalInsightsLinuxCustomLogCollection, Disable-AzureRmOperationalInsightsIISLo...
Script 4.1.2 AzureRM.PowerBIEmbedded {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollectionAccessKeys, Get-AzureRmPowerBIWorkspace...}
Script 4.3.0 AzureRM.Profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}
Script 4.0.2 AzureRM.RecoveryServices {Get-AzureRmRecoveryServicesBackupProperty, Get-AzureRmRecoveryServicesVault, Get-AzureRmRecoveryServicesVaultSettingsFile, New-AzureRmRecoveryServicesVault...}
Script 4.1.0 AzureRM.RecoveryServices.Backup {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmRecoveryServicesBackupManagementServer, Get-AzureRmRecoveryServicesBackupContainer, Unregister-AzureRmRecoveryServicesBackupContainer...}
Script 0.2.1 AzureRM.RecoveryServices.SiteRec... {Edit-AzureRmRecoveryServicesAsrRecoveryPlan, Get-AzureRmRecoveryServicesAsrAlertSetting, Get-AzureRmRecoveryServicesAsrEvent, Get-AzureRmRecoveryServicesAsrFabric...}
Script 4.1.0 AzureRM.RedisCache {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCacheScheduleEntry, Get-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCachePatchSchedule...}
Script 0.3.1 AzureRM.Relay {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-AzureRmRelayNamespace, Remove-AzureRmRelayNamespace...}
Script 0.1.1 AzureRM.Reservations {Get-AzureRmReservationOrder, Get-AzureRmReservation, Get-AzureRmReservationHistory, Update-AzureRmReservation...}
Script 5.4.0 AzureRM.Resources {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Get-AzureRmRoleAssignment, New-AzureRmRoleAssignment...}
Script 0.16.1 AzureRM.Scheduler {Disable-AzureRmSchedulerJobCollection, Enable-AzureRmSchedulerJobCollection, Get-AzureRmSchedulerJobCollection, Get-AzureRmSchedulerJob...}
Script 4.1.0 AzureRM.ServerManagement {Invoke-AzureRmServerManagementPowerShellCommand, Get-AzureRmServerManagementSession, New-AzureRmServerManagementSession, Remove-AzureRmServerManagementSession...}
Script 0.6.1 AzureRM.ServiceBus {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace, Set-AzureRmServiceBusNamespace, Remove-AzureRmServiceBusNamespace...}
Script 0.3.1 AzureRM.ServiceFabric {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmServiceFabricClientCertificate, Add-AzureRmServiceFabricClusterCertificate, Add-AzureRmServiceFabricNode...}
Script 5.0.4 AzureRM.SiteRecovery {Get-AzureRmSiteRecoveryFabric, New-AzureRmSiteRecoveryFabric, Remove-AzureRmSiteRecoveryFabric, Stop-AzureRmSiteRecoveryJob...}
Script 4.2.0 AzureRM.Sql {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseTransparentDataEncryptionActivity, Set-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseUpgradeHint...}
Script 4.2.1 AzureRM.Storage {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-AzureRmStorageAccount, New-AzureRmStorageAccountKey...}
Script 4.0.2 AzureRM.StreamAnalytics {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnalyticsDefaultFunctionDefinition, New-AzureRmStreamAnalyticsFunction, Remove-AzureRmStreamAnalyticsFunction...}
Script 0.1.1 AzureRM.Subscription.Preview {Get-AzureRmSubscriptionDefinition, New-AzureRmSubscriptionDefinition}
Script 4.0.0 AzureRM.Tags {Remove-AzureRmTag, Get-AzureRmTag, New-AzureRmTag}
Script 4.0.1 AzureRM.TrafficManager {Disable-AzureRmTrafficManagerEndpoint, Enable-AzureRmTrafficManagerEndpoint, Set-AzureRmTrafficManagerEndpoint, Get-AzureRmTrafficManagerEndpoint...}
Script 4.0.1 AzureRM.UsageAggregates Get-UsageAggregates
Script 4.1.0 AzureRM.Websites {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-AzureRmAppServicePlan, Remove-AzureRmAppServicePlan...}

Get-Module -Name AzureRM -ListAvailable

Environment Data

Name                           Value
----                           -----
PSVersion                      5.1.17134.48
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.48
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3

Debug Output

PS C:\________\localScripts> $DebugPreference = "Continue"
Select-AzureRmSubscription –Subscriptionid $SubscriptionID

DEBUG: 12:38:52 PM - SetAzureRMContextCommand begin processing with ParameterSet 'Subscription'.
DEBUG: 12:38:52 PM - using account id 'Administrator.EA.Craig@volparasolutions.com'...
DEBUG: 12:38:52 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 12:38:52 PM - No autosave setting detected in environment variable 'AzureRmContextAutoSave'. 
DEBUG: 12:38:52 PM - Using Autosave scope 'CurrentUser'
DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '2bdb9991- -', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedir
ect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthrity: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/2bdb9991- -/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: '2bdb9991- -', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientR
edirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - AcquireTokenHandlerBase: === Token Acquisition started:
	Authority: https://login.microsoftonline.com/2bdb9991- -/
	Resource: https://management.core.windows.net/
	ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
	CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (6 items)
	Authentication Target: User
	

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:52:  - TokenCache: Deserialized 6 items to token cache.

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - TokenCache: Looking up cache for a token...

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - TokenCache: An item matching the requested resource was found in the cache

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - TokenCache: 693.534526786667 minutes left until token in cache expires

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - TokenCache: A matching item (access token or refresh token or both) was found in the cache

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:52: 8152acf9-2147-47d8-a365-7bf3552d409c - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was retuned:
	Access Token Hash: 1ju6Wz2UBo/3D8Jm961Pi4mhC1dQhhv+AwLwGOHLMeY=
	Refresh Token Hash: iv8v4wJ8Mwk59xJNf1Z7RdFimFbIsJxoaVFkiTI+D5o=
	Expiration Time: 05/24/2018 12:12:24 +00:00
	User Hash: Fk/O+2JNVktNP4PX5FBlPBWXprd1VTVncIBby22LclE=
	

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/tenants?api-version=2016-06-01

Headers:
x-ms-client-request-id        : b4adb22d-214e-466c-b102-9fc28f1fe4fa
accept-language               : en-US

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-tenant-reads: 14996
x-ms-request-id               : 4559abb8-1319-4496-971c-69d8dc7fcd26
x-ms-correlation-request-id   : 4559abb8-1319-4496-971c-69d8dc7fcd26
x-ms-routing-request-id       : AUSTRALIACENTRAL:20180524T003854Z:4559abb8-1319-4496-971c-69d8dc7fcd26
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Thu, 24 May 2018 00:38:54 GMT

Body:
{
  "value": [
    {
      "id": "/tenants/2bdb9991
      "tenantId": "2bdb9991
    }
  ]
}


DEBUG: [Common.Authentication]: Authenticating using configuration values: Domain: '2bdb9991-', Endpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientRedir
ect: 'urn:ietf:wg:oauth:2.0:oob', ResourceClientUri: 'https://management.core.windows.net/', ValidateAuthrity: 'True'
DEBUG: [Common.Authentication]: Acquiring token using context with Authority 'https://login.microsoftonline.com/2bdb9991- -/', CorrelationId: '00000000-0000-0000-0000-000000000000', ValidateAuthority: 'True'
DEBUG: [Common.Authentication]: Acquiring token using AdalConfiguration with Domain: '2bdb9991-', AdEndpoint: 'https://login.microsoftonline.com/', ClientId: '1950a258-227b-4e31-a9cf-717495945fc2', ClientR
edirectUri: urn:ietf:wg:oauth:2.0:oob
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - AcquireTokenHandlerBase: === Token Acquisition started:
	Authority: https://login.microsoftonline.com/2bdb9991- -/
	Resource: https://management.core.windows.net/
	ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
	CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (6 items)
	Authentication Target: User
	

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:53:  - TokenCache: Deserialized 6 items to token cache.

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - TokenCache: Looking up cache for a token...

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - TokenCache: An item matching the requested resource was found in the cache

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - TokenCache: 693.520825653333 minutes left until token in cache expires

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - TokenCache: A matching item (access token or refresh token or both) was found in the cache

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : 
DEBUG: 05/24/2018 00:38:53: ce83bb36-d367-4714-bf53-25c7ad40d458 - AcquireTokenHandlerBase: === Token Acquisition finished successfully. An access token was retuned:
	Access Token Hash: 1ju6Wz2UBo/3D8Jm961Pi4mhC1dQhhv+AwLwGOHLMeY=
	Refresh Token Hash: iv8v4wJ8Mwk59xJNf1Z7RdFimFbIsJxoaVFkiTI+D5o=
	Expiration Time: 05/24/2018 12:12:24 +00:00
	User Hash: Fk/O+2JNVktNP4PX5FBlPBWXprd1VTVncIBby22LclE=
	

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions?api-version=2016-06-01

Headers:
x-ms-client-request-id        : 01c4b29a-884b-4ac8-a50d-910b58fc0f6a
accept-language               : en-US

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-tenant-reads: 14996
x-ms-request-id               : 4e505f00-bd39-435f-87b2-e9f78775ecdf
x-ms-correlation-request-id   : 4e505f00-bd39-435f-87b2-e9f78775ecdf
x-ms-routing-request-id       : AUSTRALIACENTRAL:20180524T003855Z:4e505f00-bd39-435f-87b2-e9f78775ecdf
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Thu, 24 May 2018 00:38:54 GMT

Body:
{
  "all the details for our 40+ subscriptions removed for security sake"
}




Name             : Customer - Sadd---------- - f709cc73-----------------
Account          : Administrator
SubscriptionName : Customer - Sadd-------------
TenantId         : 2bdb9991
Environment      : AzureCloud

DEBUG: AzureQoSEvent: CommandName - Set-AzureRmContext; IsSuccess - True; Duration - 00:00:02.3748728; Exception - ;
DEBUG: Finish sending metric.
DEBUG: 12:38:56 PM - SetAzureRMContextCommand end processing.
DEBUG: 12:38:56 PM - SetAzureRMContextCommand end processing.



@cormacpayne
Copy link
Member

@dufc1923 would you mind upgrading to the latest version of AzureRM.Profile and seeing if this issue persists?

@dufc1923
Copy link
Author

Hi there,

I've updated the module, its now showing version 5.1.0 and it does now seem to be working.
Thanks for the suggestion..
I'll keep an eye on it.

Cheers,
Craig

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Script 5.1.0 AzureRM.profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}
Script 5.0.1 AzureRM.profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}

Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager

ModuleType Version Name ExportedCommands


Script 4.3.0 AzureRM.Profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}

@dufc1923 dufc1923 reopened this May 28, 2018
@dufc1923
Copy link
Author

Issue has returned..
I have the latest version installed..

same issue as before..

PS C:> get-module azureRM.Profile -listavailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Script 5.1.0 AzureRM.profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}
Script 5.0.1 AzureRM.profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}

Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager

ModuleType Version Name ExportedCommands


Script 4.3.0 AzureRM.Profile {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}

@DdenBraver
Copy link

DdenBraver commented May 31, 2018

I have exactly the same issue after updating to azurerm version 6.1.1.
I will for now be reverting back to version 6.0.1

Update:
Version that has the issue:
Clean install of AzureRm 6.1.1
AzureRm.Profile 5.1

Issue:
Cannot select certain subscriptions using Set-AzureRmContext.
Strange thing is is that it seems to be random.
I can for example go to subscription A,C,D,F. Then restart my session and I can only connect to subscription A,B,C,E.
If I cannot connect to a subscription, it will connect back to the current subscription instead.

@NateB2
Copy link

NateB2 commented May 31, 2018

I'm experiencing the same issue with 6.1.0.

@markcowl
Copy link
Member

markcowl commented May 31, 2018

@NateB2 @DdenBraver @dufc1923 Can you execute:

Get-AzureRmContext -ListAvailable

Also, try typing Select-AzureRmContext <space> and then tabbing through the available contexts to see if anything else is there.

You can also always use
Disconnect-AzureRmAccount or Get-AzureRmContext | Remove-AzureRmContext -Force

Whenever there appears to be a problem with the saved context, And then open a new session, and log in again.

If you are runnign interactively, you can run

Clear-AzureRmContext

To start fresh after any context-related issue.

@NateB2
Copy link

NateB2 commented May 31, 2018

@markcowl - we're seeing the problem on VSTS build agents when running the Azure PowerShell task. Some of our subscriptions work great and others don't. It appears to be random.

When I run Get-AzureRmContext from a PowerShell window on the build agents, it says I need to run Login-AzureRmAccount first.

@markcowl
Copy link
Member

markcowl commented Jun 1, 2018

@NateB2 So, if the issue is with VSTS, it seems unrelated to the above issue, and may be related to the change in context autosave settings. You should likely turn off context autosave for the user running the VSTS powershell scripts. (i.e. Disable-AzureRmContextAutosave)

@DdenBraver
Copy link

DdenBraver commented Jun 4, 2018

@NateB2 @markcowl , the original issue we had was indeed also with an account that is also being used in VSTS.
I will do some additional testing with Clear-AzureRmContext & Disable-AzureRmContextAutosave.
Will keep you updated.

@DdenBraver
Copy link

DdenBraver commented Jun 4, 2018

@markcowl Our issue seems to be related to a double login.
We use Account A to handle action A, and another Account B handle action B.

It seems that when we connect with account B, and connect to a context that is also available in Account A that we cannot connect to its context.

For some reason this always worked when using the older AzureRm module. And the latest combination where this still works fine is AzureRm 6.0.1 with AzureRm.Profile 5.0.1

Example code to reproduce:

# Login 1
write-output 'Connecting with AzureRunasCredentials'
$RunAsConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
$null = Add-AzureRmAccount -ServicePrincipal `
                           -TenantId $RunAsConnection.TenantId `
                           -ApplicationId $RunAsConnection.ApplicationId `
                           -CertificateThumbprint $RunAsConnection.CertificateThumbprint 

$Subscriptions = get-azurermsubscription
Foreach ($Subscription in $Subscriptions){
    $Context = Set-AzureRmContext -subscriptionobject $subscription
    write-output "Connected to Subscription $($Context.Name) (should be $($Subscription.Name))"
}

# Login 2
write-output 'Connecting with ADCredentials'
$ADCredential = Get-AutomationPSCredential -Name 'ADCredentials'
$null = Add-AzureRmAccount -Credential $ADCredential

$Subscriptions = get-azurermsubscription
Foreach ($Subscription in $Subscriptions){
    $Context = Set-AzureRmContext -subscriptionobject $subscription
    write-output "Connected to Subscription $($Context.Name) (should be $($Subscription.Name))"
}

image

To fix this issue, I added [Disconnect-AzureRmAccount] in between Login 1 and Login 2.

@markcowl
Copy link
Member

markcowl commented Jun 7, 2018

@dufc1923 @DdenBraver @NateB2 Disconnecting the account is appropriate, when you have completed using those credentials, there may even be some underlying issue in switching between SPN and UPN for the same subscription (we'll take a look).

In any case where you are running automation, it is good practice to use

Disable-AzureRmContextAutosave -Scope Process

At the beginning of your script. This disconnects your context from any dependency on the file system, which should speed things up dramatically in some cases, and prevent your scripts from interfering with each other, if running simultaneously.

@markcowl
Copy link
Member

markcowl commented Jun 7, 2018

@dufc1923 @NateB2 @DdenBraver BTW - Clear-AzureRmContext is not a good solution when running in automation, you should really start a new session after clearing the context. Disconnecting the account or removing the context should be the appropriate solution.

@markcowl
Copy link
Member

markcowl commented Jun 7, 2018

@dufc1923 Can you comment on whether using Disconnect-AzureRmAccount or Remove-AzureRmContext or Clear-AzureRmContext resolves your issue?

@dufc1923
Copy link
Author

dufc1923 commented Jun 7, 2018

@markcowl , The only one of those suggestuins that I've used is Disable-AzureRmContextAutosave and that does seem to have helped.

The first workaround I used however was to use
Set-AzureRMContext -SubscriptionId $subscriptionId -TenantId $tenantId

It seemed like specifying the subscription AND the tenant also helped to get me going again.

Hope that's useful for others.

@DdenBraver
Copy link

DdenBraver commented Jun 11, 2018

@markcowl, those cmdlets did not work as a work-around for us.
It seems that in our case the subscription context of a previous user is saved/kept after reboot or even after a re-login.
We are currently working together with Premier support on this issue,

Set-AzureRMContext -SubscriptionId $subscriptionId -TenantId $tenantId also did not do the trick for us.

@vladimir-shcherbakov vladimir-shcherbakov removed this from the 2018-06-15 milestone Jun 19, 2018
@vladimir-shcherbakov vladimir-shcherbakov added this to the 2018-06-29 milestone Jun 19, 2018
@markcowl
Copy link
Member

@DdenBraver This is because you have context autosave enabled. Running Disable-AzureRmContextAutosave -Scope Process at the start of every automated script will ensure the script is isolated from previously saved contexts.

The context is saved in user accound AppData by default. If you have multiple scripts that do login runnign simultaneously in this account, then you may consider turning off context autosave globally: Disable-AzureRmContextAutosave -Scope CurrentUser which turns off context autosave altogether for all sessions all the time.

@markcowl markcowl reopened this Jun 19, 2018
@markcowl
Copy link
Member

Closing as the workaround worked for the original issue. Tracking the fix for the root cause here: #6489

@DdenBraver Since your issue appears to be different than this, if the above advice does not fix it, please file an issue with your particular issue details.

@DdenBraver
Copy link

Thanks @markcowl!
I will start tracking #6489 ,the current work-around is sufficient for now.

@NateB2
Copy link

NateB2 commented Jun 25, 2018

@markcowl - the workaround worked for us as well - thanks!

@Eagle-85
Copy link

@markcowl
Adding 'Disable-AzureRmContextAutosave' and using 'Disconnect-AzureRmAccount' instead of 'Remove-AzureRmContext' seems to have fixed the issue for us. We were having a problem with Select-AzureRmSubscription not always working when the script was called from a Scheduled Task.

Thank you.

@DdenBraver
Copy link

@Neblua Do you still have this issue when using the latest version?
I am currently testing with AzureRm 6.3.0 and AzureRm.Profile 5.3.0 and have not run into issues yet*

@Eagle-85
Copy link

Eagle-85 commented Jul 3, 2018

@DdenBraver after removing all azurerm modules and installing using the 6.3 MSI it appears to always work now when selecting subscription and when run as a scheduled task.

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

9 participants