There are ways to bypass manual authentication where you need to fill in credentials. In this guide, I will show you a smart way to bypass this. This guide is for MFA-disabled/excluded users.
OBS it’s not recommended. This is more for automate powershell script (in Task Scheduler) with service account.
- You begin with creating a .txt file and store your encrypted password. The following cmdlet will do it. You will only need to type this manually ONCE!Read-Host -assecurestring | convertfrom-securestring | out-file C:\mysecurestring.txt
- Now you will predefine your credentials:$username = “YourUserName”
$password = Get-content “C:\mysecurestring.txt” | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password - The only thing left is to connect your predefined credentials with the authentication.
$credentials = get-credential -credential $cred
Connect-Exchangeonline -credential $credentials
Now you will be able to trigger a script without needing authentication!