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

[Az.Storage] Get-AzStorageAccount can't access classic blob storage accounts.

Open chaami opened this issue 7 years ago • 11 comments

Description

Listing the storage accounts associated to the subscription will omit the classic instances.

Steps to reproduce

Set-AzContext -Subscription "someSubscriptionWithClassicBlobStorageAccounts"
Get-AzStorageAccount

Storage accounts of Storage account (classic) type will not show up in the returned table.

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.2
PSEdition                      Core
GitCommitId                    6.2.2
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     2.8.0      Az                                  Core,Desk
Script     1.6.3      Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosave, E… Script     1.0.1      Az.Advisor                          Core,Desk {Get-AzAdvisorRecommendation, Enable-AzAdvisorRecommend… Script     1.0.2      Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksCreden… Script     1.1.1      Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnalysisSer…
Script     1.3.2      Az.ApiManagement                    Core,Desk {Add-AzApiManagementApiToProduct, Add-AzApiManagementPr… Script     1.0.2      Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzApplicationInsights, … Script     1.3.4      Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Remove-AzAutomation… Script     1.1.2      Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAccount, Get-AzBatch…
Script     1.0.1      Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-AzEnrol… Script     1.3.1      Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzCdnPro… Script     1.2.1      Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-AzCognitiveService… Script     2.7.0      Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, New-A… Script     1.0.1      Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerGroup, Remove-AzC… Script     1.1.0      Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContainerRegistry, Upda… Script     1.4.0      Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-AzDat… Script     1.0.1      Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New-AzDataLakeAnaly… Script     1.2.3      Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDataLak… Script     1.0.1      Az.DeploymentManager                Core,Desk {Get-AzDeploymentManagerArtifactSource, New-AzDeploymen… Script     1.0.0      Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutdownPo… Script     1.1.1      Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove-AzDn… Script     1.2.2      Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridTopic, Set-AzEven…
Script     1.4.0      Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNamespace, Set-… Script     1.1.1      Az.FrontDoor                        Core,Desk {New-AzFrontDoor, Get-AzFrontDoor, Set-AzFrontDoor, Rem… Script     2.0.2      Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefinition,… Script     1.0.0      Az.HealthcareApis                   Core,Desk {New-AzHealthcareApisService, Remove-AzHealthcareApisSe… Script     1.3.1      Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGroup, Ge…
Script     1.3.1      Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCertificat… Script     1.3.1      Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get-AzIntegrationAc… Script     1.1.1      Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-AzMlCommitmentAsso… Script     1.0.1      Az.ManagedServices                  Core,Desk {Get-AzManagedServicesAssignment, New-AzManagedServices… Script     1.0.1      Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.1.0      Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKey, Set-AzMediaServiceKey, … Script     1.4.0      Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLogProf…
Script     1.15.0     Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate, Get… Script     1.1.0      Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificationHubAuthorizat… Script     1.3.3      Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivityLogDataSource, N… Script     1.1.3      Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolicyStat…
Script     1.1.0      Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerBIWork… Script     1.4.5      Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRecoverySe… Script     1.1.1      Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-AzRedisCacheSche… Script     1.0.2      Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNamespace, Set-AzRela… Script     1.7.0      Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment, Get-…
Script     1.4.0      Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServiceBusNamespace, … Script     1.2.0      Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricApplicationCertificate, Add-AzServi… Script     1.1.0      Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, New-Az… Script     1.15.0     Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get-AzSqlD… Script     1.8.0      Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, New-AzS…
Script     1.2.1      Az.StorageSync                      Core,Desk {Invoke-AzStorageSyncCompatibilityCheck, New-AzStorageS… Script     1.0.0      Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyticsDe… Script     1.0.2      Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndpoint, Remove-AzT… Script     1.5.0      Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-AzAppS…

In order to generate SAS tokens, I had to access the blob storage context through the instance string with New-AzStorageContext and feed that to New-AzStorageAccountSASToken

Kind regards.

chaami avatar Oct 18 '19 15:10 chaami

Hi @chaami , thanks for your report. Can you offer us more debug info to help us find the reason?

  1. You can find the module installed on your computer:
Get-Module -ListAvailable
  1. You can find the debug info by run the cmdlet with -Debug:
Get-AzStorageAccount -Debug

Remember delete the info of your company.

Thanks

wyunchi-ms avatar Oct 19 '19 03:10 wyunchi-ms

This is by design, unfortunately 'classic' storage accounts use RDFE. You woyuld need to use the 'Azure' module to manage these in PowerShell scripts.

markcowl avatar Oct 21 '19 06:10 markcowl

@markcowl Thanks for the precision. Given that the Azure module and Az module cannot be installed on the same host, this is quite a burden... Does that mean that to handle Cloud Services, I need to keep an Azure module around as well ? I don't see anything in the new API about them...

chaami avatar Oct 21 '19 08:10 chaami

In case someone else is suffering from this, the storage accounts are showing up when using Get-AzResource (but not the cloud services though which is a completely different topic 😅 )

chaami avatar Oct 21 '19 16:10 chaami

Was this ever resolved? Or is the work-around to use Get-AzResource? That command doesn't give me what I need for my classic storage account. I basically need to retrieve the primary key which, in the past, was accomplished by using (Get-AzurestorageKey -StorageAccountName).Primary. Get-AzResource doesn't give me the capability of doing that. Any thoughts?

afaruqi avatar Jan 14 '20 22:01 afaruqi

All,

I am experiencing similar issue where I need to grab the storage account key. I have PS Core and CLI installed on my machine but not the classic "Azure" module. I had installed it at one point but it created issues between the versions so I removed it.

Using Get-AzResource, I can get the classic SA's info... that was it. To get the key, I would need to use some the on Azure module it seems or maybe thru some REST calls? This is so frustrating.

UltraGC avatar Oct 19 '20 18:10 UltraGC

Was this ever resolved? Or is the work-around to use Get-AzResource? That command doesn't give me what I need for my classic storage account. I basically need to retrieve the primary key which, in the past, was accomplished by using (Get-AzurestorageKey -StorageAccountName).Primary. Get-AzResource doesn't give me the capability of doing that. Any thoughts?

Did you find an answer to this?

UltraGC avatar Oct 19 '20 19:10 UltraGC

Sorry to bear sad news @UltraGC , but I had to keep an older modules installation around in order to run the older commands. The piece of good news is that they still work (sometimes the server side of the commands is shut without warnings). And you can forget about accessing the storage through the cli some day. I would advise to use a key vault secret to store the key or a share access signature to the blob storage and get it from there. There still must be a way to access it because the Azure Storage Explorer manages to list them all... Good luck ! 🤞

chaami avatar Oct 19 '20 22:10 chaami

@chaami Bummer. Thanks for the info.

UltraGC avatar Oct 19 '20 22:10 UltraGC

Use the API directly for classic storage account key:

$token = (Get-AzAccessToken).Token $keys = Invoke-RestMethod -Method POST -Uri https://management.azure.com/subscriptions/{your subscription}/resourceGroups/{your resourcegroup}/providers/Microsoft.ClassicStorage/storageAccounts/{your account}/listKeys?api-version=2016-11-01 -Headers @{"Authorization"="Bearer $token"}

$keys.primaryKey $keys.secondaryKey

BellaLi avatar Mar 12 '21 20:03 BellaLi

If you have AZ installed

$resources = $(az resource list --query "[?name=='$name']") | Convertfrom-Json
$storage = $resources | Where-Object { $_.type -eq "Microsoft.ClassicStorage/storageAccounts" }
$uri = $storage.id + "/listKeys" + "?api-version=2016-11-01"
$classickeys = (az rest --method post --uri $uri) | Convertfrom-Json
$key = $classickeys.primaryKey

mikeblakeuk avatar Sep 09 '21 16:09 mikeblakeuk