0
votes

I'm trying to create an automation which involves connecting to exchange online. I'm unable to achieve this because whenever I issue the Connect-Exchange command with valid credentials provided, it asks for MFA (multi-factor authentication) - which cannot be automated. How can I achieve an automation with this? Any ideas? Thanks!

$password = ConvertTo-SecureString 'MySecretPassword' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ('user@company.com', $password)
Connect-ExchangeOnline -Credential $credential
1
You don't currently. Either set up a SPN or use an account that does not have MFA enabled.Scepticalist

1 Answers

0
votes

To expand on the point that Scepticalist made, you will do this by creating a Service Principal in AzureAD, assign it the appropriate rights in Exchange Online and then setup certificate based or client secrets based authentication. This approach replaces your existing interactive user that use for running scripts and doesn't involve MFA because it isn't a traditional user.

More information can be found here: https://www.michev.info/Blog/Post/2997/connecting-to-exchange-online-powershell-via-client-secret-flow