I use the following code to create a credential object then connect to MS Online services:
$password = ConvertTo-SecureString "XXXX" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist admin@mycompany.onmicrosoft.com, $password
$session = New-CsOnlineSession -Credential $cred
Import-PSSession $session -AllowClobber -verbose
Connect-MsolService -Credential $cred
This code has worked without issue for a while but running it today I got the following error:
Connect-MsolService : Authentication Error: Unexpected authentication failure.
When I remove the -Credential option from the Connect-MsolService command and use the interactive form, everything works fine (hence I know that the username and password are correct).
Any ideas?
Thanks
Simon