Before we can automate a script and just having it fail, I wrote a script that will allow you to test connectivity to M365 Services. This way we can report out that we are not connected instead of the script failing and leaving us to figure out why it failed. The script can be found in my Github repository @ Microsoft365/Test-M365 Connection.ps1 at main · MWPatterson2000/Microsoft365 (github.com)