title: How to login from an Azure Resource Manager Runbook?
body: <p>Using the new Azure portal, I am trying to add a powershell runbook that will start a specific VM. This is not something that will be run in powershell from my PC, it will instead run as an ARM job. I can't seem to find a way to successfully login.</p>
  
  <p>If running from my desktop in powershell I can just call Login-AzureRmAccount and it will launch a login dialog before running any further steps. From what I've read on the web it seemed that what I needed to do was add a credential to my automation account, retrieve it and then call the same Login method. I've now done that, but still can't log in.</p>
  
  <pre><code>Import-Module AzureRM.Compute
  $AutomationCredentialAssetName = "automation"
  $Cred = Get-AutomationPSCredential -Name $AutomationCredentialAssetName
  Write-Output $Cred
  Login-AzureRmAccount -Credential $Cred
  Start-AzureRmVm -Name 'myvmname' -ResourceGroupName 'myresourcegroupname'
  </code></pre>
  
  <p>The credential is being retrieved correctly (get's written to output) but the call to the Login-AzureRmAccount fails with:</p>
  
  <p>Login-AzureRmAccount : unknown_user_type: Unknown User Type
  At line:10 char:1
  + Login-AzureRmAccount -Credential $Cred
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Add-AzureRmAccount], AadAuthenticationFailedException
      + FullyQualifiedErrorId : Microsoft.Azure.Common.Authentication.AadAuthenticationFailedException,Microsoft.Azure.Com
  mands.Profile.AddAzureRMAccountCommand</p>
  
  <p>If I don't attempt to log in first I get a message telling me to call Login-AzureRmAccount first.</p>
  
  <p>How do I authenticate from within a runbook so that I can run automation tasks? What am I doing wrong?</p>