I had a weird issue at work a little bit ago when trying to work with Exchange which was still on premise. I was tasked with gathering a list of mailboxes and exporting the permissions on a list of folders including a list of special folders (example: Deletions).
I was connecting into an exchange 2010 environment and did this by executing the RemoteExchange.ps1 script.
. "c:\Program Files\Microsoft\Exchange Server\v14\bin\RemoteExchange.ps1" connect-exchangeserver -auto
Now here is the odd part. When I would then import the module ActiveDirectory, the shell would crash - and this would happen consistently. My environment running into this issue is Windows 10 with the latest updates, running Windows PowerShell 5.1.
Since the error caused the shell to close, I could not see the error it displayed on the screen right away and had to go through the event viewer. There were no errors logged in Event Viewer, and the information and warnings didn't shed any light on the situation. So out of curiosity, I tried to get a mailbox, and after it was successfully retrieved I imported the Active Directory module and the error came back. So after re-opening the console, I tried to get an invalid mailbox and then imported the Active Directory module and the console didn't crash.
I then imported the CSV file again and ran the rest of the code - and it worked.
I closed the shell, added in a line to my script to get an invalid mailbox before importing the Active Directory module and the error went away.
So what did I learn from this?
1. Sometimes unconventional troubleshooting is needed. I took the script step by step until I found the error and then changed as many variables as I could until I finally found a path that allowed the process to go as planned.
2. Unexpected interactions sometimes cause errors that you may not always see ahead of time, so it's important to know what these differences are and to document them to be able to quickly fix them for the future.
3. Documenting weird issues are important - not only for myself but for others as well. I will not remember everything - and sometimes I need to be able to search through my own history to find something that went wrong before.