Secure password rejected as bad but thats incorrect Share on Facebook Tweet on Twitter Share on LinkedIn Home › Forums › Scripting › PowerShell › Secure password rejected as bad but thats incorrect Tagged: Office 365 This topic contains 1 reply, has 2 voices, and was last updated by wullieb1 2 weeks, 2 days ago. Viewing 2 posts - 1 through 2 (of 2 total) Author Posts confuseisParticipant September 2, 2019 at 2:43 pm #623404 Hi Im doing some work with office 365 Im looking to automate a task Im using below code but getting error on the last line “Connect-Msolservice : Authentication error: Bad username or password. Problem is the password works perfectly everywhere for me dont see why im getting such error so dont know how to troubleshoot. Searched online to no avail so far. $username = “Mickey” $password = “KnownGoodPassword” $securePWD = $password | ConvertToSecureString -AsPlainText -Force $MyCredential = NewObject -typename System.Management.Automation.PSCredential -Argumentlist $username,$securePWD Import-Module MSonline Connect-MSOlService -credential $MyCredential wullieb1Moderator September 2, 2019 at 8:35 pm #623407 Are you trying to automate the password side of things by having your password in a text format? Here’s what i would do, and which i do as its a security risk having credentials stored in plain text: $MyCredential = Get-Credential Import-Module MSonline Connect-MSOlService -credential $MyCredential I’d also have a look here if you really need to do this, https://techcommunity.microsoft.com/t5/Office-365/cred-Get-Credential-without-asking-for-prompts-in-powershell/m-p/483274 Basically this from what i can see $username = “[email protected]” $password = ConvertTo-SecureString “mypassword” -AsPlainText -Force $psCred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password) Import-Module MSOnline Connect-MSolService -Credential $psCred $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell-liveid/ -Credential $psCred -Authentication Basic -AllowRedirection Import-PSSession $Session -AllowClobber -DisableNameChecking Author Posts Viewing 2 posts - 1 through 2 (of 2 total) You must be logged in to reply to this topic.