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
Thank you! That did the trick.
ReplyDeleteOf course, you need to have the Exchange management tools installed as well. Otherwise your script silently continues but does nothing.
ReplyDeleteYou 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!
ReplyDeletethis is the best solution ever.
ReplyDeleteThank you Peter
It worked
ReplyDeleteYES!!!!!
ReplyDeleteThank you !
ReplyDeleteI have been searching the solution for hours. Thank You!!!
ReplyDeleteThanks, was looking for this, can it harm if i set it on top of all my exchange PS1 scripts?
ReplyDeletethanks !!!!
ReplyDeletethx, so much.
ReplyDeleteIt worked. Thanks!!
ReplyDeleteThanks. this did the trick
ReplyDeleteYou are a fucking legend. Same issue as anonymous, my Exchange shell no longer loads this and i was FREAKING OUT!!!! Thank you SOOOOO much!
ReplyDeletethanks!!!
ReplyDeleteThank you so much!!!
ReplyDeleteThanks!!!!! so much, was searching for solution like this
ReplyDeleteThank you thank you thank you!!!!!! This fixed my problem with remotely administering exchange through powershell!!!
ReplyDeleteThank 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.
ReplyDeleteYou would need to add the cmdlet to your powershell profile
DeleteHere's some info in the link below:
http://www.howtogeek.com/50236/customizing-your-powershell-profile/
Awesome job, thank you.
ReplyDeleteBEST man, THE BEST, thanks very much.
ReplyDeleteSearched far and wide for this! thanks
ReplyDeletei love you dude, thanks so much!
ReplyDeletei love you dude, thanks so much!
ReplyDeleteThank you from the Netherlands! ;)
ReplyDeleteThank you in 2018!!
ReplyDeleteThank you it worked for me on 2010 Exchange
ReplyDeleteTHIS WORKED
ReplyDeleteOn-prem exhange 2008 server - get-mailbox cmdlet not recognized
-Opened elevated powershell then ran add-pssnapin *exchange* -erroraction SilentlyContinue
Get-mailbox worked!
thank you!!
god knows what causes this, but thank you!
ReplyDeleteWow! Thank you so much. So many complicated options out there but this was very simple and precise.
ReplyDeleteSame here. This solution from Peter WORKED for me on Exchange 2013. Thanks Peter --Ike E.
ReplyDelete