title: Add-AzureRmAccount : Sequence contains no elements
body: <p>I'm trying to validate a script to connect to Azure via PowerShell.</p>
  
  <pre><code>$username = "asdfasdf"
  $password = "asdfasdf"
  $secstr = New-Object -TypeName System.Security.SecureString
  $password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
  $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
  Add-AzureRmAccount -Credential $cred
  Select-AzureRmSubscription -SubscriptionId asdfasdf
  </code></pre>
  
  <p>Full error message:</p>
  
  <pre><code>Add-AzureRmAccount : Sequence contains no elements
  At C:\Users\Martin\Documents\Tasks\Azure Script ARM API Syntax Conversion\Connect Azure V1.ps1:6 char:1
  + Add-AzureRmAccount -Credential $cred
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : CloseError: (:) [Add-AzureRmAccount], AadAuthenticationFailedException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand
  </code></pre>
  
  <p>I saw here <a href="https://stackoverflow.com/questions/39657391/login-azurermaccount-cant-login-to-azure-using-pscredential">Login-AzureRmAccount can&#39;t login to Azure using PSCredential</a> that perhaps special characters may cause an error but I tried escaping the one <code>!</code> in my password without success. What else could be causing this problem?</p>