Cindy Gross: Small Bites of Big Data, Small Data, All Data

Small Bites of Big Data, Small Data, All Data for Hadoop, SQL Server, Hive, Distributed Systems, Scale Out....

PowerShell for Azure cmdlets: Subscription was all Wacky

PowerShell for Azure cmdlets: Subscription was all Wacky

Rate This
  • Comments 1

I was working on some HDInsight scripts in PowerShell and doing lots of experimenting. I’m not sure what exactly I did but all of a sudden everything stopped working. With lots of interruptions from meetings and chats and lunch…. I couldn’t retrace my steps. Everything seemed to fail on the Azure subscription information so I tried to get really basic – what did Get-AzureSubscription|%{$_.SubscriptionName} return? As it turns out, wacky garbage:

set-azuresubscription ?

What I expected to see was my single subscription:


So what happened? The Azure portal only shows one subscription. Obviously those other lines are not valid subscriptions – they look like the output of a help command or an error. Reinstalling the cmdlets, rebooting, and reimporting certificates didn’t help. I turned to my AzureCAT coworkers for help and @elcid98 pointed out this blog post that talks about how subscriptions are used in PowerShell:

Azure Subscriptions in PowerShell demystified

This caught my attention: “The second file – DefaultSubscriptionData.xml – also lists the available subscriptions and the associated certificates’ thumbprints“. Ok, where is that file? A search finds it in

C:\Users\%username%\AppData\Roaming\Windows Azure Powershell

I checked and sure enough, where I would expect just one entry I see multiple – and they’re named the same thing as the garbage in my output! I cleared out all but one entry to end up with this:

<?xml version="1.0" encoding="utf-8"?>
< Subscriptions xmlns:xsd="" xmlns:xsi="" version="0" xmlns="urn:Microsoft.WindowsAzure.Management:WaPSCmdlets">
< Subscription name="sqlcatwoman">
  < SubscriptionId>You don’t get to see the real info!</SubscriptionId>
  <Thumbprint>Not here either!</Thumbprint>
  < ServiceEndpoint></ServiceEndpoint>
< /Subscription>
< /Subscriptions>

Hmmmm…. I still got an error from Get-AzureSubscription. Back to C:\Users\%username%\AppData\Roaming\Windows Azure PowerShell. What’s this? WindowsAzureProfile.xml also has all the same junk! I cleared out all the extras to end up with this:

<?xml version="1.0" encoding="utf-8"?>
< ProfileData xmlns:i="" xmlns="">
  < DefaultEnvironmentName>AzureCloud</DefaultEnvironmentName>
  <Environments />
    < AzureSubscriptionData>
      < ActiveDirectoryEndpoint></ActiveDirectoryEndpoint>
      < ActiveDirectoryTenantId>More secrets!</ActiveDirectoryTenantId>
      < ActiveDirectoryUserId></ActiveDirectoryUserId>
      < CloudStorageAccount i:nil="true" />
      < IsDefault>true</IsDefault>
      < LoginType i:nil="true" />
      < ManagementCertificate>Hiding this one too!</ManagementCertificate>
      < ManagementEndpoint></ManagementEndpoint>
      <RegisteredResourceProviders xmlns:d4p1="" />
      < SubscriptionId>And more secrets</SubscriptionId>
< /ProfileData>

Success! Get-AzureSubscription now returns just my single, valid subscription. All my other Azure cmdlets magically started working again. I don’t know how it got that way, but at least now I know where the subscription information is stored. I hope this helps someone else with their Azure subscription PowerShell scripting!

  • Thanks!  While I think this whole subscription piece should be more "dynamic", your post certainly helped me our!

Page 1 of 1 (1 items)
Leave a Comment
  • Please add 4 and 3 and type the answer here:
  • Post