Secure password rejected as bad but thats incorrect

Home Forums Scripting PowerShell Secure password rejected as bad but thats incorrect

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Avatar wullieb1 2 weeks, 2 days ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • Avatar
    confuseis
    Participant
    #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

    Avatar
    wullieb1
    Moderator
    #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

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.