{"id":80335,"date":"2016-10-17T00:01:25","date_gmt":"2016-10-17T07:01:25","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=80335"},"modified":"2024-08-14T09:42:50","modified_gmt":"2024-08-14T16:42:50","slug":"speed-up-remote-powershell-connection-to-exchange","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/speed-up-remote-powershell-connection-to-exchange\/","title":{"rendered":"Speed up remote PowerShell connection to Exchange"},"content":{"rendered":"<p><strong>Summary<\/strong>: Speed up the connection to Exchange by importing only the cmdlets that you need.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> Is there a way to speed up the initial PowerShell connection to Exchange?<\/p>\n<p style=\"padding-left: 30px;\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/> Yes, of course! With a little modification to <strong>Import-PSSession<\/strong>, we can speed up the connection. Normally, you would connect to Exchange 2010\/2013\/2016 like this:<\/p>\n<p style=\"padding-left: 60px;\"><code>$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'http:\/\/ex01\/PowerShell\/?SerializationLevel=Full' -Authentication Kerberos\nImport-PSSession -Session $session<\/code><\/p>\n<p style=\"padding-left: 30px;\">This would import all available cmdlets in the local PowerShell session. But, consider the next example:<\/p>\n<p style=\"padding-left: 60px;\"><code>$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'http:\/\/ex01\/PowerShell\/?SerializationLevel=Full' -Authentication Kerberos\nImport-PSSession -Session $session -CommandName Get-Mailbox,New-Mailbox,Enable-Mailbox,Set-Mailbox -FormatTypeName *<\/code><\/p>\n<p style=\"padding-left: 30px;\">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:<\/p>\n<p style=\"padding-left: 60px;\"><code>Import-Module -Name ActiveDirectory -Cmdlet Get-ADUser,New-ADUser,Set-ADUser<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>Post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\" rel=\"noopener\">Official Scripting Guys Forum<\/a>. Also, check out my <a href=\"https:\/\/blogs.technet.microsoft.com\/msoms\/\" target=\"_blank\" rel=\"noopener\">Microsoft Operations Management Suite Blog<\/a>.<\/p>\n<p style=\"padding-left: 90px;\">\n","protected":false},"excerpt":{"rendered":"<p>Summary: Speed up the connection to Exchange by importing only the cmdlets that you need. Is there a way to speed up the initial PowerShell connection to Exchange? 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 [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[568,641],"tags":[27,56,700,3,45],"class_list":["post-80335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-windows-powershell","tag-exchange","tag-guest-blogger","tag-richard-diphoorn","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Speed up the connection to Exchange by importing only the cmdlets that you need. Is there a way to speed up the initial PowerShell connection to Exchange? 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 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=80335"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/80335\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=80335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=80335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=80335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}