There are two things to do when connecting remotely to Exchange in a PowerShell script module within ARS.
- First is the make sure that you're always making use of the Disconnect-PSSession cmdlet. This on its own can make a significant difference if it's not currently implemented in your scripts.
- Second is using the -CommandName parameter on the Import-PSSession cmdlet. This allows you to only import the cmdlets that you will require during your sessions. This drastically reduces the resources that are used during the PS sessions. Please see the following Microsoft article for more information on the Import-PSSession cmdlet: