I’ve seen and known many scripts that interact with Exchange Online for extended periods of time. After a while, Exchange Online likes it if you reconnect, this can be an Impliciet Authentication popup, or it can simply drop you based on what command you’re using.
If you call the following function every loop in whatever you’re doing, it’ll automatically force a reconnect to Exchange Online every hour (adjustable if you prefer longer):
Edit: read v2 of this post 🙂
Note: if you run this script in an Exchange Shell, something in the Exchange Shell modules will still prompt for reconnects every 1-2 days. In a normal PS window, I’ve verified it working for up to a week until it asks for a reconnect.
Hey there – I’m curious, when would you need this? Do you have an example of a situation that would require a long running script? I’ve just simply had a scheduled task on a server that runs every hour or 24 hours and it connects each time.
Thanks!