Speed up remote PowerShell connection to Exchange

Doctor Scripto

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

Note: This post is submitted by Richard Diphoorn, also known as rdtechie, or dippie ?, who is a Microsoft IT Professional, PowerShell.org Forum Helper and Contributor, Microsoft PowerShell Forum helper, PowerShell Saturday Organizer, and most of all, a friendly geek. Richard loves to automate everything he can, and, preferably, with PowerShell. He sees everyday as a new possibility to learn something and to help the community. So, please don’t hesitate to contact him on any of your favorite social network:

https://twitter.com/rdtechie

https://nl.linkedin.com/in/richarddiphoorn

Very kind regards, Richard Diphoorn

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

0 comments

Discussion is closed.

Feedback usabilla icon