Here are limitations about Exchange online and Security & Compliance PowerShell sessions:
Have you tried to connect them from PowerShell rather than script directly?
I connect to the Exchange online first, then connect to the Security & Compliance. Both sessions exist:
I could run both Exchange online and Security & Compliance commands:
The "Get-Mailbox" command contained in Exchange online rather than Security & Compliance.
The "Get-ComplianceSearchAction" command contained in the Security & Compliance rather than Exchange online.
I tried to connect Security & Compliance first, then Exchange online. It also works.
You can also try to connect to them with different accounts, such as using admin A to connect to Exchange online, then using admin B to connect to "Security & Compliance". If you still cannot connect from PowerShell in this way. I would suggest you confirm with Windows Server side, check whether there exists any configuration to limit your client only create one session.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.