Tuesday, January 27, 2015

Solving Just About Every Azure Login Problem That Exists

Oh. My. God. I recently rolled off of one project and onto another. Any other consultants out there know that this is no small walk in the park. You have to close up all your duties for one client, take care of all the interim stuff like feedback and resume updates and skills assessments, and then start gearing up for the next gig. In my case, I didn't just find myself in a war zone... I was smack dab in No Man's Land during trench warfare.

And yes, you continually update your resume as a consultant. It's a lot like your job is to keep finding new jobs. You make yourself as marketable as you can while trying to prove yourself when it counts so the right people later say the right things. The smart ones race against the learning curve so that they can one day catch up to it and then start defining it. Okay, maybe it's not that much different from any other job after all.

I came across something I just had to share. I was tearing my hair out trying to get Azure's PowerShell module to start working... again. It was working without any sort of problem. Then, while I still had the shell open, I start seeing this:

Text: Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your Azure credentials.
Okay. I'll run the cmdlet I ran to get started in the first place even though you could just grow some eyeballs and look about 10 lines above you to see that I already have an account! And so I do...


Microsoft Accounts Really, Really Suck at Being Completely Awesome

Microsoft came out with this brilliant idea that you could have one single account for all of your Windows devices where all your common settings are saved and shared automatically. It's honestly a fantastic idea. I'm not sure if Google Chrome's account sharing features came first or second, but Microsoft envisioned that it would be like that--which it is--and that it would be that great--which it isn't. 

The problem that they ran into is that they were also ramping up their cloud services platforms and wanted to roll those all into the MS Account as well. That wasn't all, either... they just started lumping any and all Microsoft-related accounts under the same credential umbrella. As it stands right now, I use the same email address to access my organizational account for Office 365 and whatnot, to log into my personal account which also happens to be attached to MSDN and Azure, and also for certifications.

Add to this the confusion that all your old accounts that you used to log into Microsoft environments with suddenly became Microsoft accounts. Gmail, Yahoo, Hotmail (which became Outlook.com and is actually quite awesome), and even random Exchange addresses all magically became unified. Not to each other, mind you, but in a confusing mish-mash of spiderwebs that remarkably never touch each other.

Russian Roulette with Your Sanity

Every once in a while, I'll boot up PowerShell ISE to work on my script that endlessly provisions new Azure virtual machines and configures them any which way I want. But then I discover that the game's over before it started.

After you get the error message I showed above, you'll try to add an Azure account to your Azure PowerShell configuration. But the problem is that you already have done that. In fact, chances are that you can run these two cmdlets and the output will be correct for both:

Get-AzureAccount

Get-AzureSubscription

If you decide to run Add-AzureAccount again, it might just work, honestly. I had it work 2 or 3 times before it went insane. It would pop up and say, "You're already logged in, dude. Why are you trying to log on again?" 

I'd click "Remain logged in with this account" and then it would prompt me for my password. When I put in my password, I would get a message on my Microsoft Account mobile app asking me to approve the request. This is first machine I ever configured for access to the two-factor authentication and it's never had an issue otherwise. So, I approve the request, and then it tells me, "Dude. You again? I just told you, you're already logged in. Just remain logged in with..."

And you get the point. Eventually, it just started cycling between asking for email AND password and pinging my phone once a second to approve the requests. I had to just re-install the app because of how badly my PC was misbehaving. 

Man... I hope someone finds this post and I can save them some frustration. This one had me wanting to unlearn computers.

Enough of This -- Let's Fix Every Azure Login Issue


Just do this. Instead of logging in with an email address each time, it stores a very long hash. It's like it gives it a nickname. Just imagine that Azure is cozying up to your Microsoft Account.

You still have to log in the first time -- and I'm not promising that problems won't come up ever again -- but this is quick.

1. Get-AzureSubscription | Remove-AzureSubscription


If you have a whole bunch of accounts and they're all working for you, don't run this. It clears out all your Azure subscriptions from cache. It DOES NOT affect anything on your account:


You might want to clear all your subscriptions, honestly. This method of configuration was designed specifically for this purpose.

2. Get-AzureAccount

Just check to see what's still hanging around. It shouldn't display anything. You can pipe that cmdlet to, you guessed it, Remove-AzureAccount if you want to clear everything and start fresh.

3. Get-AzurePublishSettingsFile

This opens up a webpage which immediately prompts you to save a file. Put it anywhere you want, but do yourself a favor and copy the path while you're there. You'll be finding it within PowerShell. Or just put it somewhere like C:\PS so you don't have to type a lot.

Don't bother reading the instructions on that page. They aren't really applicable right now.

4. Import-AzurePublishSettingsFile "<File location>"

Once you get that .publishsettings file imported, you'll see that your account is now much harder to remember than your email address. Mission accomplished!

But seriously, now run an Azure cmdlet like Get-AzureVM. Viola.

If you ever run into again, just do step 1 and step 4 again. You don't need get a new file each time. Heck, you could just modify $PROFILE so that it clears it each time you open PowerShell. But that's probably not necessary.

No comments:

Post a Comment