diff --git a/src/Common/Storage/Commands.Storage/Common/Cmdlet/NewAzureStorageContext.cs b/src/Common/Storage/Commands.Storage/Common/Cmdlet/NewAzureStorageContext.cs index d7847888a6fe..2a13b7213800 100644 --- a/src/Common/Storage/Commands.Storage/Common/Cmdlet/NewAzureStorageContext.cs +++ b/src/Common/Storage/Commands.Storage/Common/Cmdlet/NewAzureStorageContext.cs @@ -338,9 +338,9 @@ internal CloudStorageAccount GetStorageAccountWithAzureEnvironment(StorageCreden { AzureEnvironment azureEnvironment = null; - if (null != DefaultContext) + if (null != SMProfile) { - if (string.IsNullOrEmpty(azureEnvironmentName) ) + if (DefaultContext != null && string.IsNullOrEmpty(azureEnvironmentName)) { azureEnvironment = DefaultContext.Environment; @@ -354,7 +354,7 @@ internal CloudStorageAccount GetStorageAccountWithAzureEnvironment(StorageCreden { try { - var profileClient = new ProfileClient(new AzureSMProfile()); + var profileClient = new ProfileClient(SMProfile); azureEnvironment = profileClient.GetEnvironmentOrDefault(azureEnvironmentName); } catch(ArgumentException e)