How to pass O365 credentials automatically and securely for scheduled tasks
With everything we can do in any O365 Admin Portal possible to do, even easier and better, in PowerShell, I have tried to create scripts to automate as much of my tasks as possible. When I run these manually its fine, I enter my credentials and approve my MFA popup on Authenticator App. But what about scripts I want to run regularly, or automatically based on another event happening? Well, basically we need a few things. The first is to have an O365 Admin account, with only the bare minimum role we need, created and NOT enabled for MFA. This is a risk of course but if it can be restricted and controlled (think Conditional Access here) within your environment then this will be more of a benefit than it is a risk. Once we create this account, we now need to securely save the credentials somewhere so they can be used in an automated/scheduled task. Storing credentials securely Step 1: Store your credentials in a variable - for this session only On the server you are going to run ...