Tag Archives: powershell

Add-AzureAccount – The Data is Invalid

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 -Debug and -Verbose command 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!
Advertisements

Using PowerShell with Windows Azure

At the May 26, 2011 Boston Azure User Group meeting, Joel Bennett – a Microsoft PowerShell MVP from the Rochester, NY area – spoke about PowerShell basics, then got into a bunch of useful ways PowerShell can be applied to Windows Azure. We had around 25 people at the event.

[Update 23-June-2011: Joel Bennett posted his slide deck from the talk.] 
[Update 05-July-2011: Added another handy link to post from Patrick Butler called Developing and Debugging Azure Management API CmdLets.]

Some of the pointers:

  • Go get the PowerShell Community Extensions (from codeplex)
  • You can use the PS command line to CD into folders/directories, look at files, etc. — but you can also look at the Registry or your Certificate Store as if they were directories!
  • There are no plural nouns in PS (e.g., get-provider, not get-providers)
  • Learn these commands first: Get-Command, Get-Help, Get-Member, Select-Object, Where-Object, Format-Table, … others you can learn later
  • Somebody needs to write a PowerShell Provider for Azure Storage
  • Joel created an open-shell WPF-ish PowerShell shell called POSH

Try some commands:

  • dir | get-objec
  • dir | fl *  —formats as lis
  • get-verb | fw -col
  • get-verb | fw -col 6 -groupby Group
  • Get-ExecutionPolicy
  • dir | where { $_.PSIsContainer } — where $_ is “the thing over there (directory)”
  • dir | select CreationTime, Name | gm
  • dir | select * —will look different than command above
  • $global:foo = “some value”
  • cd c:\windows\system32\windowspowershell\v1.0… see Help.format.ps1xml controls the default output formatting properties for object types not already known by PowerShell – can have property names, even script blocks in it – very powerful
  • # is single-line comment char; <# … #> for multi-line comments
  • You can create aliases for scripts
  • Powershell is an interpreted scripting language
  • Can access WinForms, WPF, lots of stuff.. though not Threading

Three ways to manage Azure from PowerShell

  1. Remoting
  2. WASM (Windows Azure Services Management commandlets) – superceded by http://wappowershell.codeplex.com/ – developed by Development Evangelist group (e.g., Vittorio)
  3. Cerebrata (3rd party, commercial)

Remoting:

  • Need to get some goodness in a Startup Script, along with crecentials
  • Set OS Family = 2 (so you get Windows Server 2008 R2)
  • Need a certificate – can be self-signed

WAP PowerShell:

  • 36 Cmdlets
  • “the 80% library”
  • very good example

Cerebrata Cmdlets

  • Requires .NET 4.0 (which is different than baseline support for PS, which is .NET CLR 2.0
  • $70
  • 114 Cmdlets
  • Cerebrata
  • gcm –mo cerebrata | gr0up Noun | sort

Snap-ins need to be in the GAC – so put WAP PowerShell stuff where you want to keep them, since that’s where they’ll be built — or build the file in Visual Studio

  • Add-Module is for SNAPINS
  • IPMO is for ImportModule for Modules
  • ipmo AzurePlatform
  • gcm –mo AzurePlatform

PowerShell has something called “splatting”

  • Starting with a hashtable… put in the parms you’ll need
  • variables start with $
  • retrieving (splatting) starts with @

Both cerebrata and WAP are snap-ins

WHAT FOLLOWS… are somewhat random notes I captured…

Get-Certificate $azure | Get-HostedCertificateStore

Your personal profile for PowerShell lives in c:\Users\YOURNAME\Documents\WindowsPowerShell\Modules\AzurePlatform as Startup.ps1 (?)

Two kinds of errors in PowerShell: 1. Terminating Errors (exceptions, can be “trapped” or use try/catch as of PS2) and 2. Non-Terminating Errors which are harder to deal with

$? ==> did the last command succeed

dir doesnotexist –ev er –ea “”

$er[0].categoryinfo

“Don’t Produce Snap-ins!” Here’s why: to figure out what is in there (get-command –Module

Get-Module –ListAvailable

– run the above on AZure and see “NetworkLoadBalancingCl…” – is this Azure relate

OTHER INTERESTING POWERSHELL/AZURE LINKS