Friday, 18 January 2013

Enabling Exchange Cmdlets in Powershell

In order to run Exchange Server commands within a Powershell script, the relevant cmdlets need to be 'called' within Powershell.

This is accomplished with the following line, which is found at the start of nearly all of my Powershell scripts.

#Enable Exchange cmdlets
add-pssnapin *exchange* -erroraction SilentlyContinue

If you attempt to run Exchange commands in Powershell (eg. Get-Mailbox) without loading the Exchange cmdlets first, you will get an error similar to the following;

The term 'get-mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
+ get-mailbox <<<< 
    + CategoryInfo          : ObjectNotFound: (get-mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


  1. Thank you! That did the trick.

  2. Of course, you need to have the Exchange management tools installed as well. Otherwise your script silently continues but does nothing.

  3. You are a lifesaver! I had to run this within my Exchange Shell on my Exchange 2013 server in order to get the Exchange commands to work. I have no idea why it doesn't run automatically!

  4. this is the best solution ever.
    Thank you Peter

  5. I have been searching the solution for hours. Thank You!!!

  6. Thanks, was looking for this, can it harm if i set it on top of all my exchange PS1 scripts?

  7. thx, so much.

  8. It worked. Thanks!!

  9. Thanks. this did the trick

  10. You are a fucking legend. Same issue as anonymous, my Exchange shell no longer loads this and i was FREAKING OUT!!!! Thank you SOOOOO much!

  11. Thanks!!!!! so much, was searching for solution like this

  12. Thank you thank you thank you!!!!!! This fixed my problem with remotely administering exchange through powershell!!!

  13. Thank you very much for the tip. It worked well, but after a restart again I have to use this commands to enable cmdlets. Any way to keep it permanent? Thanks again.

    1. You would need to add the cmdlet to your powershell profile
      Here's some info in the link below: