0
votes

Having a hell of a day with Azure Powershell.

After much effort, I've got some of the commandlets working e.g. Get-AzureSubscription -Current returns details of my subscription.

Not sure if this is relevant, but one of the details it returns is CurrentStorageAccountName which is empty. Not sure if that is the same as target of the Get-AzureStorageAccount commandlet.

Get-AzureStorageAccount returns the following, verbatim:

Get-AzureStorageAccount : An error occurred while sending the request. At line:1 char:1 + Get-AzureStorageAccount -StorageAccountName "mensch" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-AzureStorageAccount], HttpRequestException + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.WindowsAzure.Commands.ServiceManagement.S torageServices.GetAzureStorageAccountCommand

I assumed that when I ran Set-AzureSubscription commandlet earlier that it succeeded, but it gives no message either way. But I uploaded a certificate and ran that command with the relevant thumbprint and thought I was on my way.

Any ideas why Get-AzureStorageAccount is not working for me?

3

3 Answers

0
votes
I am not sure of the exact sequence of steps you have followed so listing the steps that I followed on a clean environment
// Get the subscription file. This should open a browser and give you an option to download the settings file
PS C:\> Get-AzurePublishSettingsFile

// Import the file that was downloaded
PS C:\> Import-AzurePublishSettingsFile  C:\Temp\settings.publishsettings


PS C:\> Get-AzureSubscription -Current
SubscriptionName                         : <snip>
SubscriptionId                           : <snip>
ServiceEndpoint                          : https://management.core.windows.net/
ResourceManagerEndpoint                  :
GalleryEndpoint                          :
ActiveDirectoryEndpoint                  :
ActiveDirectoryTenantId                  :
ActiveDirectoryServiceEndpointResourceId :
SqlDatabaseDnsSuffix                     : <snip>
IsDefault                                : True
Certificate                              : <snip>
CurrentStorageAccountName                :
ActiveDirectoryUserId                    :
TokenProvider                            : <snip>


// This retrieves the storage account  detils
PS C:\> Get-AzureStorageAccount
VERBOSE: 11:28:12 PM - Begin Operation: Get-AzureStorageAccount
VERBOSE: 11:28:13 PM - Completed Operation: Get-AzureStorageAccount


StorageAccountDescription :
AffinityGroup             :
Location                  : West US
GeoReplicationEnabled     : True
GeoPrimaryLocation        : West US
GeoSecondaryLocation      : East US
Label                     : <snip>
StorageAccountStatus      : Created
StatusOfPrimary           : Available
StatusOfSecondary         : Available
Endpoints                 : <snip>
StorageAccountName        : <snip>
OperationDescription      : Get-AzureStorageAccount
OperationId               : <snip>
OperationStatus           : Succeeded

Came across a blog that list the steps http://blogs.msdn.com/b/umits/archive/2012/11/16/manage-your-windows-azure-with-powershell.aspx

0
votes

I started all over again and I think the problem was possibly in the way I made the certificate. I previously used SelfSSL to create it.

This time, I ran the following command:

makecert -sky exchange -r -n "CN=name of cert" -pe -a sha1 -len 2048 -ss My "E:\AzureCert.cer"

No idea why this should have made a difference.

0
votes

This could be an issue with authentication. I saw this same, rather useless, error when using an invalid management cert to connect. Using Fiddler, I could see Azure was returning 403's (Forbidden). Make sure you have a valid management certificate.

You can perform the following steps to set up a certificate/connection to Azure. This is an alternative to the Import-AzurePublishSettingsFile method.

1. Get a msgmt cert for the subscription
2. Upload the cert to Azure if not already
3. Install the cert into the local computer store (My)
4. Run the following:

$subID = "<replaceWithYourId>"
$thumbprint = "<replaceWithYourThumbprint>"
$myCert = Get-Item cert:\LocalMachine\My\$thumbprint
$localSubName = "<replaceWithYourSubscriptionName>"

        Set-AzureSubscription –SubscriptionName $localSubName –SubscriptionId $subID -Certificate $myCert

        $defaultStorageAccount = '<replaceWithYourStorageAccountName>'
        Set-AzureSubscription -SubscriptionName $localSubName -CurrentStorageAccount   $defaultStorageAccount

        Select-AzureSubscription -SubscriptionName $localSubName