October 17th, 2016

Speed up remote PowerShell connection to Exchange

Doctor Scripto
Scripter

Summary: Speed up the connection to Exchange by importing only the cmdlets that you need.

Hey, Scripting Guy! Question Is there a way to speed up the initial PowerShell connection to Exchange?

Hey, Scripting Guy! Answer Yes, of course! With a little modification to Import-PSSession, we can speed up the connection. Normally, you would connect to Exchange 2010/2013/2016 like this:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'http://ex01/PowerShell/?SerializationLevel=Full' -Authentication Kerberos Import-PSSession -Session $session

This would import all available cmdlets in the local PowerShell session. But, consider the next example:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'http://ex01/PowerShell/?SerializationLevel=Full' -Authentication Kerberos Import-PSSession -Session $session -CommandName Get-Mailbox,New-Mailbox,Enable-Mailbox,Set-Mailbox -FormatTypeName *

This would import only those cmdlets that you use, and this speeds up the import itself. This same kind of trick works also for the Active Directory module:

Import-Module -Name ActiveDirectory -Cmdlet Get-ADUser,New-ADUser,Set-ADUser

 

Post your questions on the Official Scripting Guys Forum. Also, check out my Microsoft Operations Management Suite Blog.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.