{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-powershell/issues/1309","labels_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1309/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1309/comments","events_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1309/events","html_url":"https://github.com/Azure/azure-powershell/issues/1309","id":117414571,"number":1309,"title":"Login-AzureRmAccount or Add-AzureRmAccount not accepting passing PSCredential objects","user":{"login":"MaxTrinidad","id":7338470,"avatar_url":"https://avatars.githubusercontent.com/u/7338470?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxTrinidad","html_url":"https://github.com/MaxTrinidad","followers_url":"https://api.github.com/users/MaxTrinidad/followers","following_url":"https://api.github.com/users/MaxTrinidad/following{/other_user}","gists_url":"https://api.github.com/users/MaxTrinidad/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxTrinidad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxTrinidad/subscriptions","organizations_url":"https://api.github.com/users/MaxTrinidad/orgs","repos_url":"https://api.github.com/users/MaxTrinidad/repos","events_url":"https://api.github.com/users/MaxTrinidad/events{/privacy}","received_events_url":"https://api.github.com/users/MaxTrinidad/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Azure/azure-powershell/labels/Team","name":"Team","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-17T18:07:11Z","updated_at":"2015-11-24T02:53:42Z","closed_at":null,"body":"I'm trying to automate the some scripts to dynamically pass the Get-Credential objects to either the \"Login-AzureRmAccount\" or \"Add-AzureRmAccount\" without success.  It only work by itself with no parameters.\r\n\r\nLogin-AzureRmAccount - work with no parameters providing a pop-window.\r\n\r\nI use the following script block in many other areas to dynamically build my credentials:\r\n\r\n## - Prepare PSCredential objects:\r\n$MyAzureName = \"username@System.net\";\r\n$MyAzurePassword = ConvertTo-SecureString '$myPassw0rd1' -AsPlainText -Force;\r\n$AzureRMCredential = new-object `\r\n-typename System.Management.Automation.PSCredential `\r\n-argumentlist $MyAzureName, $MyAzurePassword;\r\n\r\nAlso, I tried using the normal Get-Credential to create the object and that didn't work either.\r\n\r\n $AzureRMCred = Get-Credential -Credential 'maxt@vvvvv.net';\r\n\r\nIn both tries, I got the following error:\r\n\r\nPS C:\\WINDOWS\\system32> Login-AzureRmAccount -Credential $AzureRMCred\r\nLogin-AzureRmAccount : AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password\r\nTrace ID: ff9cc0dd-4df0-43c6-96d1-fe039d6e8377\r\nCorrelation ID: cd11d2b9-1898-4fc6-a57b-f42cd4a1923b\r\nTimestamp: 2015-11-17 18:03:27Z: The remote server returned an error: (400) Bad Request.\r\nAt line:1 char:1\r\n+ Login-AzureRmAccount -Credential $AzureRMCred\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : NotSpecified: (:) [Add-AzureRmAccount], AadAuthenticationFailedException\r\n    + FullyQualifiedErrorId : Microsoft.Azure.Common.Authentication.AadAuthenticationFailedException,Microsoft.Azure.C\r\n   ommands.Profile.AddAzureRMAccountCommand\r\n\r\nI have verified both UserNa,me and Password were entered correct by using the following methods:\r\n1. $AzureRMCred.GetNetworkCredential().UserName\r\n2. $AzureRMCred.GetNetworkCredential().Password\r\n\r\nSomething is definitely off.\r\n\r\n<!---@tfsbridge:{\"tfsId\":5181724}-->"},"comment":{"url":"https://api.github.com/repos/Azure/azure-powershell/issues/comments/159136611","html_url":"https://github.com/Azure/azure-powershell/issues/1309#issuecomment-159136611","issue_url":"https://api.github.com/repos/Azure/azure-powershell/issues/1309","id":159136611,"user":{"login":"ToanNN","id":6165252,"avatar_url":"https://avatars.githubusercontent.com/u/6165252?v=3","gravatar_id":"","url":"https://api.github.com/users/ToanNN","html_url":"https://github.com/ToanNN","followers_url":"https://api.github.com/users/ToanNN/followers","following_url":"https://api.github.com/users/ToanNN/following{/other_user}","gists_url":"https://api.github.com/users/ToanNN/gists{/gist_id}","starred_url":"https://api.github.com/users/ToanNN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ToanNN/subscriptions","organizations_url":"https://api.github.com/users/ToanNN/orgs","repos_url":"https://api.github.com/users/ToanNN/repos","events_url":"https://api.github.com/users/ToanNN/events{/privacy}","received_events_url":"https://api.github.com/users/ToanNN/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T02:53:42Z","updated_at":"2015-11-24T02:53:42Z","body":"@MaxTrinidad  The issue was with credential initialization. You can try this one\r\n\r\n$azureAccountName =\"<your account name>\"\r\n$azurePassword = ConvertTo-SecureString \"<your password>\" -AsPlainText -Force\r\n\r\n$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword)\r\n\r\nLogin-AzureRmAccount -Credential $psCred"}}