Solved

Only import specific cmdlets from Exchange?

Posted on 2014-11-24
8
213 Views
Last Modified: 2014-11-29
I have a script that starts a PSSession to exchange server

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$exchangeserver/PowerShell/
Import-PSSession $exchangesession

Open in new window


The Import-PSSession will work just fine, however, it takes a while. I think it's because it's loading everything Exchange.
Since I'm only running a couple of cmdlets within powershell after the PSSession import, is there a way to only import specific cmdlets?

Such as Get-Mailbox, Get-User, etc.
0
Comment
Question by:garryshape
  • 3
  • 3
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Michael Ian Claridge
ID: 40463754
Hello,

This is very interesting. My understanding of PowerShell is that you cannot do this. Each cmdlet must be part of a module, modules are imported in turn importing each and every cmdlet.

I'm doing a lot of work with DSC Custom Resources at the moment and the same theory applies.

Kindest regards

Michael
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40465112
Import-pssession has some parameter which will allow you to import specific commands.. I didn't get a chance to test it but you can try and see if it works for you.

import-pssession $exchangesession -type cmdlet -name Get-Mailbox,Get-User -FormatTypeName *

Open in new window

or
import-pssession $exchangesession -commandname Get-Mailbox -formattypename *

Open in new window


Ref : http://ss64.com/ps/import-pssession.html
0
 

Author Closing Comment

by:garryshape
ID: 40465164
Amazing. I appear to have overlooked that part in the MS examples. This link is much more helpful.
Thank you
0
 
LVL 10

Expert Comment

by:Michael Ian Claridge
ID: 40465244
@Subsun AWESOME, I will take note :)
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:garryshape
ID: 40465738
Well, interestingly, my theory was wrong:
Importing the specific commands does not make the script load any faster.
It actually takes about 10 seconds longer.
I timed it because I have a Windows Form script driven by powershell and I time based on how soon the form opens up.
Consistently, with the import-pssession importing the entire module, is 10 seconds faster.

I do wonder importing specific commands helps lessen the strain on the server, if the script is being re-run multiple times, however.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40466276
Are you sure Importing the session takes the major % of the script starting time? in my experience loading the Exchange Add-in locally on exchange server itself may take 6- 10 seconds depends on the capacity of server. If you think the load time for your script is abnormal then you may post another question including the script to check if anything wrong about the script or to check if anything can be done to make it better.
0
 

Author Comment

by:garryshape
ID: 40466755
No the majority of the load time is due to the script in its entirety.
I'm just finding that for some reason, it takes about 10 seconds longer when I change the single line of code that imports the pssession to only import cmdlets (Get-Mailbox, Add-MailboxPermissions, Add-ADPermission)
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40471977
I will test this the pssession import in my environment and let you know the result..
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now