title: login to azure account without popup using powershell
body: <p>I'm trying to create Azure VM using powershell.I have also the script to create it.  </p>
  
  <p>First I need to login into Azure account : </p>
  
  <pre><code>Login-AzureRMAccount
  </code></pre>
  
  <p>This gives a pop-up to enter the credentials.</p>
  
  <p>Second I need to run the below script:</p>
  
  <pre><code>$UserName = "username"
  $Password = ConvertTo-SecureString "password" -AsPlainText -Force
  $psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)    
  New-AzureRmVm `
      -ResourceGroupName "RG1" `
      -Name "VM1" `
      -ImageName "Image1" `
      -Location "West US" `
      -Credential $psCred
  </code></pre>
  
  <p>This is creating the VM successfully.<br>
  But now , I need to make these scripts run automatically, when ever there is requirement. The problem I'm facing is, the login step gives a popup to enter the credentials which I do not want. So I have tried something like this, but didn't work.</p>
  
  <pre><code>$username = "loginname@organization.com"
  $SecurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
  $cred = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
  Login-AzureRmAccount -Credential $cred 
  </code></pre>
  
  <p>The error message it is giving is :</p>
  
  <pre><code>Login-AzureRmAccount : accessing_ws_metadata_exchange_failed: Accessing WS metadata exchange failed: The underlying connection was closed: An unexpected error occurred on a send.
  At line:4 char:1
  + Login-AzureRmAccount -Credential $cred
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : CloseError: (:) [Connect-AzureRmAccount], AadAuthenticationFailedException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand
  </code></pre>
  
  <p>Can anyone tell me what this means and how to rectify this? Thanks!</p>