I am a heavy user of PowerShell and recently I ran across an annoying problem that I didn’t find anywhere mentioned in the google. I was running the Add-AzureAccount cmdlet from the Azure PowerShell module. (Want it too? Start here. Or simply install it from the mighty Web Platform Installer.)
The Add-AzureAccount command usually pops up a login dialog so I can authenticate against my Azure account. But the behavior I was seeing never made it to that pop-up dialog – rather it quickly dumped out the following error at the command line:
Add-AzureAccount : The data is invalid. At line:1 char:1 + Add-AzureAccount + ~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
As mentioned above, I could not find useful references to Add-AzureAccount “data is invalid” via search engine, so I tried a few things. I first updated to the latest module. Didn’t help me – but you can check which version you have installed as follows:
PS> (Get-Module Azure).Version Major Minor Build Revision ----- ----- ----- -------- 0 8 11 -1
Then I tried both the
-Verbosecommand line options, which are often useful. But no difference in the output. So this was failing pretty early!
Since this might be related to some cached credentials, I tried deleting TokenCache.dat in case there was something funky there. Nope. Here is command to view – and then delete – TokenCache.dat:
gci "$env:APPDATA\Windows Azure Powershell\TokenCache.dat" ri "$env:APPDATA\Windows Azure Powershell\TokenCache.dat"
Finally, a kind sole suggested I simply try hosing out cookies from IE. That worked! Since I was in a PowerShell kind of mood, here’s how I emptied the cookie jar:
RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
(I learned of this technique on many web sites by searching for ‘clear IE browser cache command line’.)
My problem was solved, and I am back to productively using Add-AzureAccount.
Hope this helps someone!
thanks again for hosting cloud api meetup.
I am unclear why the cookie cache caused the error. Does the process run through the PS web client zone? Had you ran a prior process that created the cache data and conflicted with the Azure cmdlet? I had a chance to work with the WebClient and am still trying to understand what happens behind the scenes.
Hey Peter – I wish I had more info! I assume the cookie (or cookies) was (were) there due to prior successful or failed login attempts (I use A-AA interactively a lot), but not clear to me what happened to confuse A-AA. Not sure if I did something outside of PS to bork things for PS, or if it was something w/in PS. I don’t think I’ve used WebClient in code from this machine recently, but have used HttpClient, so perhaps possible I hosed something. Might go down as an unsolved mystery!