Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials #7110

Closed FonsecaSergio closed 6 years ago

FonsecaSergio commented 6 years ago

Description

Script/Steps for Reproduction

##############################################################################
##First screen
##############################################################################
Login-AzureRmAccount 

Save-AzureRmContext -Path "C:\SERGIO\TEMP\CONTEXT.JSON"

Get-AzureRmSqlDatabase -ResourceGroupName CSSAzureDB -ServerName Fonsecanet 
     #RUNS OK 

##############################################################################
##Second Screen
##############################################################################
Import-AzureRmContext -Path "C:\SERGIO\TEMP\CONTEXT.JSON"

Get-AzureRmSqlDatabase -ResourceGroupName CSSAzureDB -ServerName Fonsecanet
    #Get-AzureRmSqlDatabase : Your Azure credentials have not been set up or have 
    #expired, please run Connect-AzureRmAccount to set up your Azure credentials.
    #At line:1 char:1
    #+ Get-AzureRmSqlDatabase -ResourceGroupName CSSAzureDB -ServerName Fons ...
    #+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #    + CategoryInfo          : CloseError: (:) [Get-AzureRmSqlDatabase], Argume 
    #   ntException
    #    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.Database.Cmdlet.Get 
    #   AzureSqlDatabase

#Get-AzureRmSubscription
Select-AzureRmSubscription "XXXXXXXXXXXXXXXX"
Or
Set-AzureRmContext -SubscriptionId de41dc76-12ed-4406-a032-0c96495def6b

Get-AzureRmSqlDatabase -ResourceGroupName CSSAzureDB -ServerName Fonsecanet
    #RUNS OK 

Module Version


    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                                                                                                        
---------- -------    ----                                ----------------                                                                                                                        
Script     0.5.4      Azure.AnalysisServices              {Add-AzureAnalysisServicesAccount, Restart-AzureAnalysisServicesInstance, Export-AzureAnalysisServicesInstanceLog, Sync-AzureAnalysis...
Script     4.5.0      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken, New-AzureStorageTableStoredAccessPolicy, New-AzureStorageTable...}               
Script     6.8.1      AzureRM                                                                                                                                                                     
Script     6.7.0      AzureRM                                                                                                                                                                     
Script     0.6.14     AzureRM.AnalysisServices            {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnalysisServicesServer, Get-AzureRmAnalysisServicesServer, Remove-AzureRmAnalys...
Script     0.6.12     AzureRM.AnalysisServices            {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnalysisServicesServer, Get-AzureRmAnalysisServicesServer, Remove-AzureRmAnalys...
Script     6.1.5      AzureRM.ApiManagement               {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoToken, New-AzureRmApiManagementHostnameConfiguration, New-AzureRmApiManag...
Script     6.1.3      AzureRM.ApiManagement               {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementSsoToken, New-AzureRmApiManagementHostnameConfiguration, New-AzureRmApiManag...
Script     0.1.8      AzureRM.ApplicationInsights         {Get-AzureRmApplicationInsights, New-AzureRmApplicationInsights, Remove-AzureRmApplicationInsights, Set-AzureRmApplicationInsightsPri...
Script     0.1.6      AzureRM.ApplicationInsights         {Get-AzureRmApplicationInsights, New-AzureRmApplicationInsights, Remove-AzureRmApplicationInsights, Set-AzureRmApplicationInsightsPri...
Script     5.1.1      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutomationJobOutputRecord, Import-AzureRmAutomationDscNodeConfiguration, Export-A...
Script     5.0.4      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutomationJobOutputRecord, Import-AzureRmAutomationDscNodeConfiguration, Export-A...
Script     4.0.10     AzureRM.Backup                      {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerReregistration, Get-AzureRmBackupContainer, Register-AzureRmBackupContainer...} 
Script     4.0.8      AzureRM.Backup                      {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerReregistration, Get-AzureRmBackupContainer, Register-AzureRmBackupContainer...} 
Script     4.1.5      AzureRM.Batch                       {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-AzureRmBatchAccountKeys, New-AzureRmBatchAccount...}                          
Script     4.1.3      AzureRM.Batch                       {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-AzureRmBatchAccountKeys, New-AzureRmBatchAccount...}                          
Script     0.14.6     AzureRM.Billing                     {Get-AzureRmBillingInvoice, Get-AzureRmBillingPeriod, Get-AzureRmEnrollmentAccount}                                                     
Script     0.14.5     AzureRM.Billing                     {Get-AzureRmBillingInvoice, Get-AzureRmBillingPeriod, Get-AzureRmEnrollmentAccount}                                                     
Script     5.0.5      AzureRM.Cdn                         {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureRmCdnProfile, Remove-AzureRmCdnProfile...}                                
Script     5.0.3      AzureRM.Cdn                         {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-AzureRmCdnProfile, Remove-AzureRmCdnProfile...}                                
Script     0.9.10     AzureRM.CognitiveServices           {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServicesAccountKey, Get-AzureRmCognitiveServicesAccountSkus, Get-AzureRmCog...
Script     0.9.8      AzureRM.CognitiveServices           {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitiveServicesAccountKey, Get-AzureRmCognitiveServicesAccountSkus, Get-AzureRmCog...
Script     5.5.2      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New-AzureRmAvailabilitySet, Update-AzureRmAvailabilitySet...}               
Script     5.5.0      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet, New-AzureRmAvailabilitySet, Update-AzureRmAvailabilitySet...}               
Script     0.3.7      AzureRM.Consumption                 {Get-AzureRmConsumptionBudget, Get-AzureRmConsumptionMarketplace, Get-AzureRmConsumptionPriceSheet, Get-AzureRmConsumptionReservation...
Script     0.2.10     AzureRM.ContainerInstance           {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-AzureRmContainerGroup, Get-AzureRmContainerInstanceLog}                   
Script     0.2.8      AzureRM.ContainerInstance           {New-AzureRmContainerGroup, Get-AzureRmContainerGroup, Remove-AzureRmContainerGroup, Get-AzureRmContainerInstanceLog}                   
Script     1.0.10     AzureRM.ContainerRegistry           {New-AzureRmContainerRegistry, Get-AzureRmContainerRegistry, Update-AzureRmContainerRegistry, Remove-AzureRmContainerRegistry...}       
Script     1.0.8      AzureRM.ContainerRegistry           {New-AzureRmContainerRegistry, Get-AzureRmContainerRegistry, Update-AzureRmContainerRegistry, Remove-AzureRmContainerRegistry...}       
Script     5.0.3      AzureRM.DataFactories               {Remove-AzureRmDataFactory, Get-AzureRmDataFactoryRun, Get-AzureRmDataFactorySlice, Save-AzureRmDataFactoryLog...}                      
Script     0.5.10     AzureRM.DataFactoryV2               {Set-AzureRmDataFactoryV2, Update-AzureRmDataFactoryV2, Get-AzureRmDataFactoryV2, Remove-AzureRmDataFactoryV2...}                       
Script     0.5.8      AzureRM.DataFactoryV2               {Set-AzureRmDataFactoryV2, Update-AzureRmDataFactoryV2, Get-AzureRmDataFactoryV2, Remove-AzureRmDataFactoryV2...}                       
Script     5.1.4      AzureRM.DataLakeAnalytics           {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogCredent...
Script     5.1.2      AzureRM.DataLakeAnalytics           {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLakeAnalyticsCatalogCredential, Remove-AzureRmDataLakeAnalyticsCatalogCredent...
Script     6.1.2      AzureRM.DataLakeStore               {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRmDataLakeStoreFirewallRule, Se...
Script     4.0.9      AzureRM.DevTestLabs                 {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShutdownPolicy, Get-AzureRmDtlAutoStartPolicy, Get-AzureRmDtlVMsPerLabPolicy...} 
Script     4.0.7      AzureRM.DevTestLabs                 {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShutdownPolicy, Get-AzureRmDtlAutoStartPolicy, Get-AzureRmDtlVMsPerLabPolicy...} 
Script     5.0.4      AzureRM.Dns                         {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-AzureRmDnsRecordSet, Set-AzureRmDnsRecordSet...}                           
Script     5.0.2      AzureRM.Dns                         {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remove-AzureRmDnsRecordSet, Set-AzureRmDnsRecordSet...}                           
Script     0.3.7      AzureRM.EventGrid                   {New-AzureRmEventGridTopic, Get-AzureRmEventGridTopic, Set-AzureRmEventGridTopic, New-AzureRmEventGridTopicKey...}                      
Script     0.6.10     AzureRM.EventHub                    {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Set-AzureRmEventHubNamespace, Remove-AzureRmEventHubNamespace...}          
Script     0.6.8      AzureRM.EventHub                    {New-AzureRmEventHubNamespace, Get-AzureRmEventHubNamespace, Set-AzureRmEventHubNamespace, Remove-AzureRmEventHubNamespace...}          
Script     4.1.8      AzureRM.HDInsight                   {Get-AzureRmHDInsightJob, New-AzureRmHDInsightSqoopJobDefinition, Wait-AzureRmHDInsightJob, New-AzureRmHDInsightStreamingMapReduceJob...
Script     4.1.6      AzureRM.HDInsight                   {Get-AzureRmHDInsightJob, New-AzureRmHDInsightSqoopJobDefinition, Wait-AzureRmHDInsightJob, New-AzureRmHDInsightStreamingMapReduceJob...
Script     5.1.3      AzureRM.Insights                    {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRmLogProfile, Get-AzureRmLogProfile...}                                    
Script     5.1.1      AzureRM.Insights                    {Get-AzureRmMetricDefinition, Get-AzureRmMetric, Remove-AzureRmLogProfile, Get-AzureRmLogProfile...}                                    
Script     3.1.8      AzureRM.IotHub                      {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGroup, Get-AzureRmIotHubConnectionString, Get-AzureRmIotHubJob...}              
Script     3.1.6      AzureRM.IotHub                      {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGroup, Get-AzureRmIotHubConnectionString, Get-AzureRmIotHubJob...}              
Script     5.2.1      AzureRM.KeyVault                    {Add-AzureKeyVaultCertificate, Update-AzureKeyVaultCertificate, Stop-AzureKeyVaultCertificateOperation, Get-AzureKeyVaultCertificateO...
Script     5.1.1      AzureRM.KeyVault                    {Add-AzureKeyVaultCertificate, Update-AzureKeyVaultCertificate, Stop-AzureKeyVaultCertificateOperation, Get-AzureKeyVaultCertificateO...
Script     4.1.4      AzureRM.LogicApp                    {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegrationAccountCallbackUrl, Get-AzureRmIntegrationAccountCertificate, Get-Azur...
Script     4.1.2      AzureRM.LogicApp                    {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegrationAccountCallbackUrl, Get-AzureRmIntegrationAccountCertificate, Get-Azur...
Script     0.18.5     AzureRM.MachineLearning             {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentPlanUsageHistory, Remove-AzureRmMlCo...
Script     0.18.3     AzureRM.MachineLearning             {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitmentPlanUsageHistory, Remove-AzureRmMlCo...
Script     0.4.8      AzureRM.MachineLearningCompute      {Get-AzureRmMlOpCluster, Get-AzureRmMlOpClusterKey, Test-AzureRmMlOpClusterSystemServicesUpdateAvailability, Update-AzureRmMlOpCluste...
Script     0.4.6      AzureRM.MachineLearningCompute      {Get-AzureRmMlOpCluster, Get-AzureRmMlOpClusterKey, Test-AzureRmMlOpClusterSystemServicesUpdateAvailability, Update-AzureRmMlOpCluste...
Script     0.2.5      AzureRM.MarketplaceOrdering         {Get-AzureRmMarketplaceTerms, Set-AzureRmMarketplaceTerms}                                                                              
Script     0.10.4     AzureRM.Media                       {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServiceKey, Get-AzureRmMediaServiceKeys, Get-AzureRmMediaServiceNameAvailabilit...
Script     0.10.2     AzureRM.Media                       {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServiceKey, Get-AzureRmMediaServiceKeys, Get-AzureRmMediaServiceNameAvailabilit...
Script     6.6.1      AzureRM.Network                     {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-AzureRmApplicationGatewayAuthenticationCertificate, New-AzureRmApplicati...
Script     6.5.0      AzureRM.Network                     {Add-AzureRmApplicationGatewayAuthenticationCertificate, Get-AzureRmApplicationGatewayAuthenticationCertificate, New-AzureRmApplicati...
Script     5.0.3      AzureRM.NotificationHubs            {Get-AzureRmNotificationHub, Get-AzureRmNotificationHubAuthorizationRules, Get-AzureRmNotificationHubListKeys, Get-AzureRmNotificatio...
Script     5.0.6      AzureRM.OperationalInsights         {New-AzureRmOperationalInsightsAzureActivityLogDataSource, New-AzureRmOperationalInsightsCustomLogDataSource, Disable-AzureRmOperatio...
Script     5.0.4      AzureRM.OperationalInsights         {New-AzureRmOperationalInsightsAzureActivityLogDataSource, New-AzureRmOperationalInsightsCustomLogDataSource, Disable-AzureRmOperatio...
Script     1.0.4      AzureRM.PolicyInsights              {Get-AzureRmPolicyEvent, Get-AzureRmPolicyState, Get-AzureRmPolicyStateSummary}                                                         
Script     4.1.10     AzureRM.PowerBIEmbedded             {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollectionAccessKeys, Ge...
Script     4.1.8      AzureRM.PowerBIEmbedded             {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowerBIWorkspaceCollectionAccessKeys, Ge...
Script     5.5.1      AzureRM.profile                     {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}         
Script     5.4.0      AzureRM.profile                     {Disable-AzureRmDataCollection, Disable-AzureRmContextAutosave, Enable-AzureRmDataCollection, Enable-AzureRmContextAutosave...}         
Script     4.1.8      AzureRM.RecoveryServices            {Get-AzureRmRecoveryServicesBackupProperty, Get-AzureRmRecoveryServicesVault, Get-AzureRmRecoveryServicesVaultSettingsFile, New-Azure...
Script     4.1.6      AzureRM.RecoveryServices            {Get-AzureRmRecoveryServicesBackupProperty, Get-AzureRmRecoveryServicesVault, Get-AzureRmRecoveryServicesVaultSettingsFile, New-Azure...
Script     4.4.1      AzureRM.RecoveryServices.Backup     {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmRecoveryServicesBackupManagementServer, Get-AzureRmRecoveryServicesBackupContai...
Script     4.4.0      AzureRM.RecoveryServices.Backup     {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmRecoveryServicesBackupManagementServer, Get-AzureRmRecoveryServicesBackupContai...
Script     0.2.9      AzureRM.RecoveryServices.SiteRec... {Edit-AzureRmRecoveryServicesAsrRecoveryPlan, Get-AzureRmRecoveryServicesAsrAlertSetting, Get-AzureRmRecoveryServicesAsrEvent, Get-Az...
Script     0.2.8      AzureRM.RecoveryServices.SiteRec... {Edit-AzureRmRecoveryServicesAsrRecoveryPlan, Get-AzureRmRecoveryServicesAsrAlertSetting, Get-AzureRmRecoveryServicesAsrEvent, Get-Az...
Script     5.0.5      AzureRM.RedisCache                  {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCacheScheduleEntry, Get-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCache...
Script     5.0.3      AzureRM.RedisCache                  {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCacheScheduleEntry, Get-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCache...
Script     0.3.10     AzureRM.Relay                       {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-AzureRmRelayNamespace, Remove-AzureRmRelayNamespace...}                      
Script     0.3.8      AzureRM.Relay                       {New-AzureRmRelayNamespace, Get-AzureRmRelayNamespace, Set-AzureRmRelayNamespace, Remove-AzureRmRelayNamespace...}                      
Script     6.4.2      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Get-AzureRmRoleAssignment, New-AzureRmRoleAssignment...}                   
Script     6.4.0      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignment, Get-AzureRmRoleAssignment, New-AzureRmRoleAssignment...}                   
Script     0.16.10    AzureRM.Scheduler                   {Disable-AzureRmSchedulerJobCollection, Enable-AzureRmSchedulerJobCollection, Get-AzureRmSchedulerJobCollection, Get-AzureRmScheduler...
Script     0.16.8     AzureRM.Scheduler                   {Disable-AzureRmSchedulerJobCollection, Enable-AzureRmSchedulerJobCollection, Get-AzureRmSchedulerJobCollection, Get-AzureRmScheduler...
Script     0.6.11     AzureRM.ServiceBus                  {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace, Set-AzureRmServiceBusNamespace, Remove-AzureRmServiceBusNamespace...}  
Script     0.6.9      AzureRM.ServiceBus                  {New-AzureRmServiceBusNamespace, Get-AzureRmServiceBusNamespace, Set-AzureRmServiceBusNamespace, Remove-AzureRmServiceBusNamespace...}  
Script     0.3.12     AzureRM.ServiceFabric               {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmServiceFabricClientCertificate, Add-AzureRmServiceFabricClusterCertificat...
Script     0.3.10     AzureRM.ServiceFabric               {Add-AzureRmServiceFabricApplicationCertificate, Add-AzureRmServiceFabricClientCertificate, Add-AzureRmServiceFabricClusterCertificat...
Script     4.11.3     AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseTransparentDataEncryptionActivity, Set-AzureRmSqlDatabaseTran...
Script     4.11.1     AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-AzureRmSqlDatabaseTransparentDataEncryptionActivity, Set-AzureRmSqlDatabaseTran...
Script     5.0.4      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-AzureRmStorageAccount, New-AzureRmStorageAccountKey...}                   
Script     5.0.2      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, New-AzureRmStorageAccount, New-AzureRmStorageAccountKey...}                   
Script     4.0.10     AzureRM.StreamAnalytics             {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnalyticsDefaultFunctionDefinition, New-AzureRmStreamAnalyticsFunction, Remove-...
Script     4.0.8      AzureRM.StreamAnalytics             {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnalyticsDefaultFunctionDefinition, New-AzureRmStreamAnalyticsFunction, Remove-...
Script     4.0.5      AzureRM.Tags                        {Remove-AzureRmTag, Get-AzureRmTag, New-AzureRmTag}                                                                                     
Script     4.1.1      AzureRM.TrafficManager              {Add-AzureRmTrafficManagerCustomHeaderToEndpoint, Remove-AzureRmTrafficManagerCustomHeaderFromEndpoint, Add-AzureRmTrafficManagerCust...
Script     4.0.9      AzureRM.TrafficManager              {Disable-AzureRmTrafficManagerEndpoint, Enable-AzureRmTrafficManagerEndpoint, Set-AzureRmTrafficManagerEndpoint, Get-AzureRmTrafficMa...
Script     4.0.5      AzureRM.UsageAggregates             Get-UsageAggregates                                                                                                                     
Script     5.0.9      AzureRM.Websites                    {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-AzureRmAppServicePlan, Remove-AzureRmAppServicePlan...}                      
Script     5.0.7      AzureRM.Websites                    {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New-AzureRmAppServicePlan, Remove-AzureRmAppServicePlan...}                      
Script     1.0.1      Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValidation}                                                                                   
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}                                                                  
Script     3.4.0      Pester                              {Describe, Context, It, Should...}                                                                                                      
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}                                                                            
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHandler, Remove-PSReadlineKeyHandler, Get-PSReadlineOption...}                              

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    Name                                ExportedCommands                                                                                                                        
---------- -------    ----                                ----------------                                                                                                                        
Manifest   1.0.0.0    AppBackgroundTask                   {Disable-AppBackgroundTaskDiagnosticLog, Enable-AppBackgroundTaskDiagnosticLog, Set-AppBackgroundTaskResourcePolicy, Unregister-AppBa...
Manifest   2.0.0.0    AppLocker                           {Get-AppLockerFileInformation, Get-AppLockerPolicy, New-AppLockerPolicy, Set-AppLockerPolicy...}                                        
Manifest   1.0.0.0    AppvClient                          {Add-AppvClientConnectionGroup, Add-AppvClientPackage, Add-AppvPublishingServer, Disable-Appv...}                                       
Manifest   2.0.0.0    Appx                                {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest, Remove-AppxPackage...}                                                      
Script     1.0.0.0    AssignedAccess                      {Clear-AssignedAccess, Get-AssignedAccess, Set-AssignedAccess}                                                                          
Manifest   1.0.0.0    BitLocker                           {Unlock-BitLocker, Suspend-BitLocker, Resume-BitLocker, Remove-BitLockerKeyProtector...}                                                
Manifest   2.0.0.0    BitsTransfer                        {Add-BitsFile, Complete-BitsTransfer, Get-BitsTransfer, Remove-BitsTransfer...}                                                         
Manifest   1.0.0.0    BranchCache                         {Add-BCDataCacheExtension, Clear-BCCache, Disable-BC, Disable-BCDowngrading...}                                                         
Manifest   1.0.0.0    CimCmdlets                          {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, Get-CimSession...}                                                           
Manifest   1.0        ConfigCI                            {Get-SystemDriver, New-CIPolicyRule, New-CIPolicy, Get-CIPolicy...}                                                                     
Manifest   1.0        Defender                            {Get-MpPreference, Set-MpPreference, Add-MpPreference, Remove-MpPreference...}                                                          
Manifest   1.0.0.0    DeliveryOptimization                {Get-DeliveryOptimizationStatus, Get-DeliveryOptimizationPerfSnap, Get-DeliveryOptimizationLog, Get-DODownloadMode...}                  
Manifest   1.0.0.0    DirectAccessClientComponents        {Disable-DAManualEntryPointSelection, Enable-DAManualEntryPointSelection, Get-DAClientExperienceConfiguration, Get-DAEntryPointTableI...
Script     3.0        Dism                                {Add-AppxProvisionedPackage, Add-WindowsDriver, Add-WindowsCapability, Add-WindowsImage...}                                             
Manifest   1.0.0.0    DnsClient                           {Resolve-DnsName, Clear-DnsClientCache, Get-DnsClient, Get-DnsClientCache...}                                                           
Manifest   1.0.0.0    EventTracingManagement              {Start-EtwTraceSession, New-EtwTraceSession, Get-EtwTraceSession, Update-EtwTraceSession...}                                            
Manifest   1.0.0.0    HgsClient                           {Get-HgsAttestationBaselinePolicy, Get-HgsClientConfiguration, Test-HgsClientConfiguration, Set-HgsClientConfiguration...}              
Manifest   1.0.0.0    HgsDiagnostics                      {New-HgsTraceTarget, Get-HgsTrace, Get-HgsTraceFileData, Test-HgsTraceTarget}                                                           
Manifest   1.0.0.0    HostNetworkingService               {Remove-HnsNamespace, Remove-HnsEndpoint, Get-HnsEndpoint, Get-HnsNamespace...}                                                         
Manifest   2.0.0.0    International                       {Get-WinDefaultInputMethodOverride, Set-WinDefaultInputMethodOverride, Get-WinHomeLocation, Set-WinHomeLocation...}                     
Manifest   1.0.0.0    iSCSI                               {Get-IscsiTargetPortal, New-IscsiTargetPortal, Remove-IscsiTargetPortal, Update-IscsiTargetPortal...}                                   
Script     1.0.0.0    ISE                                 {New-IseSnippet, Import-IseSnippet, Get-IseSnippet}                                                                                     
Manifest   1.0.0.0    Kds                                 {Add-KdsRootKey, Get-KdsRootKey, Test-KdsRootKey, Set-KdsConfiguration...}                                                              
Manifest   1.0.1.0    Microsoft.PowerShell.Archive        {Compress-Archive, Expand-Archive}                                                                                                      
Manifest   3.0.0.0    Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...}                                                                          
Manifest   3.0.0.0    Microsoft.PowerShell.Host           {Start-Transcript, Stop-Transcript}                                                                                                     
Manifest   1.0.0.0    Microsoft.PowerShell.LocalAccounts  {Add-LocalGroupMember, Disable-LocalUser, Enable-LocalUser, Get-LocalGroup...}                                                          
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...}                                                                          
Script     1.0        Microsoft.PowerShell.ODataUtils     Export-ODataEndpointProxy                                                                                                               
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...}                                                                               
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}                                                                              
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSSP, Set-WSManQuickConfig...}                                                  
Manifest   1.0        MMAgent                             {Disable-MMAgent, Enable-MMAgent, Set-MMAgent, Get-MMAgent...}                                                                          
Manifest   1.0.0.0    MsDtc                               {New-DtcDiagnosticTransaction, Complete-DtcDiagnosticTransaction, Join-DtcDiagnosticResourceManager, Receive-DtcDiagnosticTransaction...
Manifest   2.0.0.0    NetAdapter                          {Disable-NetAdapter, Disable-NetAdapterBinding, Disable-NetAdapterChecksumOffload, Disable-NetAdapterEncapsulatedPacketTaskOffload...}  
Manifest   1.0.0.0    NetConnection                       {Get-NetConnectionProfile, Set-NetConnectionProfile}                                                                                    
Manifest   1.0.0.0    NetDiagnostics                      Get-NetView                                                                                                                             
Manifest   1.0.0.0    NetEventPacketCapture               {New-NetEventSession, Remove-NetEventSession, Get-NetEventSession, Set-NetEventSession...}                                              
Manifest   2.0.0.0    NetLbfo                             {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic, Get-NetLbfoTeam, Get-NetLbfoTeamMember...}                                                  
Manifest   1.0.0.0    NetNat                              {Get-NetNat, Get-NetNatExternalAddress, Get-NetNatStaticMapping, Get-NetNatSession...}                                                  
Manifest   2.0.0.0    NetQos                              {Get-NetQosPolicy, Set-NetQosPolicy, Remove-NetQosPolicy, New-NetQosPolicy}                                                             
Manifest   2.0.0.0    NetSecurity                         {Get-DAPolicyChange, New-NetIPsecAuthProposal, New-NetIPsecMainModeCryptoProposal, New-NetIPsecQuickModeCryptoProposal...}              
Manifest   1.0.0.0    NetSwitchTeam                       {New-NetSwitchTeam, Remove-NetSwitchTeam, Get-NetSwitchTeam, Rename-NetSwitchTeam...}                                                   
Manifest   1.0.0.0    NetTCPIP                            {Get-NetIPAddress, Get-NetIPInterface, Get-NetIPv4Protocol, Get-NetIPv6Protocol...}                                                     
Manifest   1.0.0.0    NetworkConnectivityStatus           {Get-DAConnectionStatus, Get-NCSIPolicyConfiguration, Reset-NCSIPolicyConfiguration, Set-NCSIPolicyConfiguration}                       
Manifest   1.0.0.0    NetworkSwitchManager                {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEthernetPort, Get-NetworkSwitchEthernetPort, Remove-NetworkSwitchEthernetPort...
Manifest   1.0.0.0    NetworkTransition                   {Add-NetIPHttpsCertBinding, Disable-NetDnsTransitionConfiguration, Disable-NetIPHttpsProfile, Disable-NetNatTransitionConfiguration...} 
Manifest   1.0.0.0    PcsvDevice                          {Get-PcsvDevice, Start-PcsvDevice, Stop-PcsvDevice, Restart-PcsvDevice...}                                                              
Binary     1.0.0.0    PersistentMemory                    {Get-PmemDisk, Get-PmemPhysicalDevice, Get-PmemUnusedRegion, New-PmemDisk...}                                                           
Manifest   1.0.0.0    PKI                                 {Add-CertificateEnrollmentPolicyServer, Export-Certificate, Export-PfxCertificate, Get-CertificateAutoEnrollmentPolicy...}              
Manifest   1.0.0.0    PnpDevice                           {Get-PnpDevice, Get-PnpDeviceProperty, Enable-PnpDevice, Disable-PnpDevice}                                                             
Manifest   1.1        PrintManagement                     {Add-Printer, Add-PrinterDriver, Add-PrinterPort, Get-PrintConfiguration...}                                                            
Binary     1.0.11     ProcessMitigations                  {Get-ProcessMitigation, Set-ProcessMitigation, ConvertTo-ProcessMitigationPolicy}                                                       
Script     3.0        Provisioning                        {Install-ProvisioningPackage, Export-ProvisioningPackage, Install-TrustedProvisioningCertificate, Export-Trace...}                      
Manifest   1.1        PSDesiredStateConfiguration         {Set-DscLocalConfigurationManager, Start-DscConfiguration, Test-DscConfiguration, Publish-DscConfiguration...}                          
Script     1.0.0.0    PSDiagnostics                       {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSManTrace, Enable-PSTrace...}                                                  
Binary     1.1.0.0    PSScheduledJob                      {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-JobTrigger...}                                                                  
Manifest   2.0.0.0    PSWorkflow                          {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn}                                                                            
Manifest   1.0.0.0    PSWorkflowUtility                   Invoke-AsWorkflow                                                                                                                       
Manifest   1.0.0.0    ScheduledTasks                      {Get-ScheduledTask, Set-ScheduledTask, Register-ScheduledTask, Unregister-ScheduledTask...}                                             
Manifest   2.0.0.0    SecureBoot                          {Confirm-SecureBootUEFI, Set-SecureBootUEFI, Get-SecureBootUEFI, Format-SecureBootUEFI...}                                              
Manifest   2.0.0.0    SmbShare                            {Get-SmbShare, Remove-SmbShare, Set-SmbShare, Block-SmbShareAccess...}                                                                  
Manifest   2.0.0.0    SmbWitness                          {Get-SmbWitnessClient, Move-SmbWitnessClient, gsmbw, msmbw...}                                                                          
Manifest   1.0.0.0    StartLayout                         {Export-StartLayout, Import-StartLayout, Export-StartLayoutEdgeAssets, Get-StartApps}                                                   
Manifest   2.0.0.0    Storage                             {Add-InitiatorIdToMaskingSet, Add-PartitionAccessPath, Add-PhysicalDisk, Add-StorageFaultDomain...}                                     
Manifest   2.0.0.0    TLS                                 {New-TlsSessionTicketKey, Enable-TlsSessionTicketKey, Disable-TlsSessionTicketKey, Export-TlsSessionTicketKey...}                       
Manifest   1.0.0.0    TroubleshootingPack                 {Get-TroubleshootingPack, Invoke-TroubleshootingPack}                                                                                   
Manifest   2.0.0.0    TrustedPlatformModule               {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unblock-Tpm...}                                                                                    
Binary     2.1.639.0  UEV                                 {Clear-UevConfiguration, Clear-UevAppxPackage, Restore-UevBackup, Set-UevTemplateProfile...}                                            
Manifest   2.0.0.0    VpnClient                           {Add-VpnConnection, Set-VpnConnection, Remove-VpnConnection, Get-VpnConnection...}                                                      
Manifest   1.0.0.0    Wdac                                {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDsn, Add-OdbcDsn...}                                                                           
Manifest   1.0.0.0    WindowsDeveloperLicense             {Get-WindowsDeveloperLicense, Unregister-WindowsDeveloperLicense, Show-WindowsDeveloperLicenseRegistration}                             
Script     1.0        WindowsErrorReporting               {Enable-WindowsErrorReporting, Disable-WindowsErrorReporting, Get-WindowsErrorReporting}                                                
Manifest   1.0.0.0    WindowsSearch                       {Get-WindowsSearchSetting, Set-WindowsSearchSetting}                                                                                    
Manifest   1.0.0.0    WindowsUpdate                       Get-WindowsUpdateLog                                                                                                                    
Manifest   1.0.0.2    WindowsUpdateProvider               {Get-WUAVersion, Get-WULastInstallationDate, Get-WULastScanSuccessDate, Get-WUIsPendingReboot...}                                       

    Directory: C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules

ModuleType Version    Name                                ExportedCommands                                                                                                                        
---------- -------    ----                                ----------------                                                                                                                        
Manifest   14.0       SQLPS                               {Backup-SqlDatabase, Save-SqlMigrationReport, Add-SqlAvailabilityDatabase, Add-SqlAvailabilityGroupListenerStaticIp...}                 

    Directory: C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell

ModuleType Version    Name                                ExportedCommands                                                                                                                        
---------- -------    ----                                ----------------                                                                                                                        
Binary     1.29.5.0   AzureInformationProtection          {Clear-RMSAuthentication, Get-RMSFileStatus, Get-RMSServer, Get-RMSServerAuthentication...}   

Environment Data

Name                           Value                                                                                                                                                              
----                           -----                                                                                                                                                              
PSVersion                      5.1.17134.228                                                                                                                                                      
PSEdition                      Desktop                                                                                                                                                            
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                            
BuildVersion                   10.0.17134.228                                                                                                                                                     
CLRVersion                     4.0.30319.42000                                                                                                                                                    
WSManStackVersion              3.0                                                                                                                                                                
PSRemotingProtocolVersion      2.3                                                                                                                                                                
SerializationVersion           1.1.0.1                   

$PSVersionTable

Debug Output

Get-AzureRmSqlDatabase : Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials.
At line:8 char:1
+ Get-AzureRmSqlDatabase -ResourceGroupName CSSAzureDB -ServerName Fons ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRmSqlDatabase], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.Database.Cmdlet.GetAzureSqlDatabase
oshevnin commented 6 years ago

We experience the same issue with the version Seems like TokenCache.CacheData is not deserialized/set correctly when importing context from file

leowumsft commented 6 years ago

I experience the same problem. Same versions (AzureRM 6.8.1 and AzureRM.Profile 5.5.1) like Sergio. By running "Import-AzureRmContext -Path …. -Debug", I got the following messages

DEBUG: 08/31/2018 19:20:22: - TokenCache: Deserialized 0 items to token cache. DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 08/31/2018 19:20:22: df2ff16b-2a1a-4af6-8b6a-d7379609e04e - TokenCache: Looking up cache for a token... DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 : DEBUG: 08/31/2018 19:20:22: df2ff16b-2a1a-4af6-8b6a-d7379609e04e - TokenCache: No matching token was found in the cache DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 : DEBUG: 08/31/2018 19:20:22: df2ff16b-2a1a-4af6-8b6a-d7379609e04e - AcquireTokenSilentHandler: No token matching arguments found in the cache DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Error: 4 : DEBUG: 08/31/2018 19:20:22: df2ff16b-2a1a-4af6-8b6a-d7379609e04e - d0: Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException: Failed to acquire token silently. Call method AcquireToken at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenSilentHandler.SendTokenRequestAsync() at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.d0.MoveNext() ErrorCode: failed_to_acquire_token_silently DEBUG: [Common.Authentication]: Received exception Authentication error while acquiring token: 'Failed to acquire token silently. Call method AcquireToken'., while authenticating.

markcowl commented 6 years ago

@FonsecaSergio @leowumsft @OShevnin-Quest Is there a reason why you are not using automatic context persistence? If you just use Enable-AzureRmContextAutsave -Scope CurrentUser your context will always be active whenever you open a PowerShell window.

FonsecaSergio commented 6 years ago

@markcowl this is for a job that will run unattended using Windows scheduled task

leowumsft commented 6 years ago

@markcowl, please correct me if I am wrong. That autosave feature only keep the last context but I keep flipping between multiple accounts (commercial and gov) so that feature is not helpful for me.

oshevnin commented 6 years ago

@markcowl in our scenario, we may have several activities running in parallel using different credentials (i.e. different default contexts). And each of those activities can spawn several parallel workloads. Please suggest a better solution if exists, instead of saving/restoring the context.

Thank you

AWahlqvist commented 6 years ago

Just want to chime in and say that we're also experiencing this, or at least a similar issue, especially when we have multiple processes running in parallel. Even if we run Connect-AzureRmAccount first, specifying a credential and subscription id the subsequent cmdlet intermittently fails with the "credentials have expired" error (it's quite rare though, but it does happen often enough to be real issue).

We've tried to set "Scope" to Process and specify the "SkipContextPopulation" for the Connect-AzureRmAccount cmdlet and actually thought it helped for some time, but today we started to get the same error again, it usually happens when using PowerShell jobs that run simultaneously (the Connect-AzureRmAccount is ran inside each job).

We use this in Azure Automation on Hybrid Workers and have added the AzureRmContextAutoSave environment variable (set to false).

We target hundreds of different subscriptions so the context autosave feature is really not for us.

Not sure if it's the same problem or if I should add another issue regarding this?

juancrl commented 6 years ago

Hi all,

I think I was facing a similar problem and can probably provide a solution or workaround, at least something you can test in 10 minutes.

My app connects to different Azure subscriptions for different users, one after another, and I began to face the Token/Expired Credentials since approx AzureRM 6.7.0. Now running 6.8.1, workaround is :

  1. Clear-AzureRmContext # Thanks to Mark

  2. Disable-AzureRmContextAutosave -Scope Process # Thanks to Mark, but my scope is Process

  3. Import-AzureRmContext -Path $File # Where File is an EMPTY JSON FILE (saved when no context)

  4. Dir "$($Env:Appdata)\Windows Azure Powershell" -Filter "Azure*.json" | Remove-Item -Force

  5. Now you can Import-AzureRMContext yourjsonfile.json

  6. and 4. are only needed for JSON logon, Connect-AzureRMAccount does not need them. probably only one of them is needed. Investigating further.

HTH, jc

juancrl commented 6 years ago

Update. Step 3 is needed, Step 4 is NOT needed. The file contains { "DefaultContextKey": "Default", "EnvironmentTable": {}, "Contexts": {}, "ExtendedProperties": {} } I don't know if Clear-AzureRMContext or some similar cmdlet could do the same trick...

jc

FooNagi commented 6 years ago

Hi all,

I think I was facing a similar problem and can probably provide a solution or workaround, at least something you can test in 10 minutes.

My app connects to different Azure subscriptions for different users, one after another, and I began to face the Token/Expired Credentials since approx AzureRM 6.7.0. Now running 6.8.1, workaround is :

  1. Clear-AzureRmContext # Thanks to Mark
  2. Disable-AzureRmContextAutosave -Scope Process # Thanks to Mark, but my scope is Process
  3. Import-AzureRmContext -Path $File # Where File is an EMPTY JSON FILE (saved when no context)
  4. Dir "$($Env:Appdata)\Windows Azure Powershell" -Filter "Azure*.json" | Remove-Item -Force
  5. Now you can Import-AzureRMContext yourjsonfile.json
  6. and 4. are only needed for JSON logon, Connect-AzureRMAccount does not need them. probably only one of them is needed. Investigating further.

HTH, jc

+1 👍 currently scratching my head for 3 days now! Thanks a lot man! For me only steps 1 & 2 were needed. I was able to import the saved context again. Will inform after a few days of observation.

juancrl commented 6 years ago

Happy to know it works ! Now let's hope Microsoft documents better all the Context idea, as promised. jc

FooNagi commented 6 years ago

Update: Sadly, reusing the saved context via Import and then Save still gives out errors. In order to renew it I had to manually login and save it again, as a work around we decided to use cred manager and just call it for automation purposes as a temporary fix.

etfong commented 6 years ago

Hi all, I think I was facing a similar problem and can probably provide a solution or workaround, at least something you can test in 10 minutes. My app connects to different Azure subscriptions for different users, one after another, and I began to face the Token/Expired Credentials since approx AzureRM 6.7.0. Now running 6.8.1, workaround is :

  1. Clear-AzureRmContext # Thanks to Mark
  2. Disable-AzureRmContextAutosave -Scope Process # Thanks to Mark, but my scope is Process
  3. Import-AzureRmContext -Path $File # Where File is an EMPTY JSON FILE (saved when no context)
  4. Dir "$($Env:Appdata)\Windows Azure Powershell" -Filter "Azure*.json" | Remove-Item -Force
  5. Now you can Import-AzureRMContext yourjsonfile.json
  6. and 4. are only needed for JSON logon, Connect-AzureRMAccount does not need them. probably only one of them is needed. Investigating further.

HTH, jc

+1 👍 currently scratching my head for 3 days now! Thanks a lot man! For me only steps 1 & 2 were needed. I was able to import the saved context again. Will inform after a few days of observation.

This works for me on build 6.8.1

FooNagi commented 6 years ago

@etfong have you checked again after a few days if the saved context is still reusable?

etfong commented 6 years ago

@etfong have you checked again after a few days if the saved context is still reusable?

Yes it works repeatedly

markcowl commented 6 years ago

@etfong The issue is that, when importing a context, there is no way to merge tokens from any existing context and the context you are importing. The Import should simply overwrite any existing tokens.

@etfong @OShevnin-Quest @FonsecaSergio @leowumsft @AWahlqvist Also, for everyone on the thread, if you are using azure powershell in an environment where multiple scripts are running with different credentials, here are some recommended practices:

(1) Turn off context autosave, as this will make all authentication occur in memory, and isolate each session from the context changes in other sessions (Disable-AzureRContextAutosave -Scope Process). If you are not also executing interactive cmdlets, then you can turn context autosave off for all sessions (Disable-AzureRMContextAutosave -Scope CurrentUser) (2) Authenticate at the beginning of your script, rather than relying on previous / imported contexts - Azure Automation provides default service principal authentication that should be easy to use at the beginning of scripts (3) Use service principal authentication, as this allows granular control over authorization

markcowl commented 6 years ago

Opened issue: #7456 which identifies the actual bug. If you are seeing a separate issue with authentication, please file another issue.

markcowl commented 6 years ago

Closing this issue in favor of #7456 which should resolve the underlyign issue. Meanwhile, please follow the advice above, and please file issue if you are having specific problems, or need specific advice on your authentication scenario.

yukinwoo commented 6 years ago

Hi all, I think I was facing a similar problem and can probably provide a solution or workaround, at least something you can test in 10 minutes. My app connects to different Azure subscriptions for different users, one after another, and I began to face the Token/Expired Credentials since approx AzureRM 6.7.0. Now running 6.8.1, workaround is :

  1. Clear-AzureRmContext # Thanks to Mark
  2. Disable-AzureRmContextAutosave -Scope Process # Thanks to Mark, but my scope is Process
  3. Import-AzureRmContext -Path $File # Where File is an EMPTY JSON FILE (saved when no context)
  4. Dir "$($Env:Appdata)\Windows Azure Powershell" -Filter "Azure*.json" | Remove-Item -Force
  5. Now you can Import-AzureRMContext yourjsonfile.json
  6. and 4. are only needed for JSON logon, Connect-AzureRMAccount does not need them. probably only one of them is needed. Investigating further.

HTH, jc

+1 👍 currently scratching my head for 3 days now! Thanks a lot man! For me only steps 1 & 2 were needed. I was able to import the saved context again. Will inform after a few days of observation.

This works for me on build 6.8.1

This works for me on AzureRM 6.10.0. But I should execute these clear context scripts after each Import-AzureRmContext.

Turn off context autosave for all session (Disable-AzureRMContextAutosave -Scope CurrentUser) is not effective my environment.

pixelicous commented 6 years ago

@juancrl I cannot get this to work, I am not sure what i am doing wrong.

Our scripts run jobs, prior to starting the job we run Save-AzureRmContext and save the file locally, then we run Import-AzureRmContext and we get the error message.

If we run Clear-AzureRmContext in our script then we cannot save the profile as it is out the window.. would love some explanation here, thanks a lot in advance.

juancrl commented 6 years ago

Each job runs in a separate runspace... so probably the AzureRM context has to be separated per job. I don't know what you're trying to achieve, but if each job has to run under a different user, try to do all the context clearing inside each of the job's code, not outside of it... I don't understand the "it is out the window" part. Which window are you referring to ?

pixelicous commented 6 years ago

Each job runs in a separate runspace... so probably the AzureRM context has to be separated per job. I don't know what you're trying to achieve, but if each job has to run under a different user, try to do all the context clearing inside each of the job's code, not outside of it... I don't understand the "it is out the window" part. Which window are you referring to ?

Hey Juan, I am basically trying to run async processes, for this we have to save the profile else the job will be out of context, "out the window" i meant that the account is getting cleared 😆 I will try to clear the context inside the job and see what is going on

markcowl commented 6 years ago

@pixelicious Please file a separate issue if the advice above does not work for you. We need to ensure that we have captured the details of your particular scenario. If you file an issue, the issue template will guide you to providing the correct information for us to diagnose your particular issue. Further comments on this issue make it difficult to track where there is still an active issue, and what the active issue is.

DhawalCCI commented 5 years ago

What was the solution ? I am facing the same issue in Azure Automation Runbook.

When I run the same commands locally in a PS it works fine. But when it runs via the Automation Runbook it fails.

Get-AzureRmADUser : Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials. At line:23 char:18