Save Exchange PowerShell Command

Environment: Exchange 2013

Hi All,
I am trying to accomplish what I think it pretty simple.
I have an Exchange Management Shell command (Move-ActiveMailboxDatabase command to move my active database server) and I want to save it to my desktop.  How do I go about doing it?

I want to be able to double-click the script and it execute the Powershell script.

Thank you in advance!
zito2000Network ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammad Ishtyaq khatriSr. Systems EngineerCommented:
save it to the notepad and make the extension as .ps1 like 'notepad.ps1'

You can right click the file than and click run with powershell or you can put into the batch file and run the batch by double clicking.

Below link should help in creating the batch file:
AmitIT ArchitectCommented:
Copy/paste in notepad first and then save it as .ps1.
zito2000Network ManagerAuthor Commented:
I tried the first method, and it failed.  I'm thinking because it's an Exchange Management Shell command, and not a Powershell command.
"Move-ActiveMailboxDatabase : the term 'Move-ActiveMailboxDatabase" is not recognized as the name of a cmdlet"
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

AmitIT ArchitectCommented:
You need to call the Exchange snap-in in  your command.
Tom CieslikIT EngineerCommented:
I don't think is going to work from workstation.
If you'll save as .ps1 file and double click on it it will run Windows PowerShell on your computer.

To make this command work on Exchange you need to modify link to run Exchange PowerSchell from Exchange server or install Exchange Tools on your computer

This is link where  Exchange powerschell is installed

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "

If you do have Exchange Tools installed on your PC then you can run it by replacing RemoteExchange.ps1 with your file
zito2000Network ManagerAuthor Commented:
Amit - How do I call the Exchange Snap In?
Tom - I plan on running this directly on the Exchange server, which obviously has Exchange Tools on it
Mohammad Ishtyaq khatriSr. Systems EngineerCommented:
Follow the attached document for powershell remoting into exchange :-
Tom CieslikIT EngineerCommented:
If you do on Exchange is a different story.
So create test.ps1 file and copy to let say c:\temp on Exchange
Create file let say job.bat
Inside put

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Temp\test.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell "

Create shortcut to this BAT file on your desktop and you going to be OK

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Tom is on the right track, but not walking the full distance 😁.
You run
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell; & 'Path and filename of your script' "

Open in new window

AmitIT ArchitectCommented:
Try out Tom advise above.
zito2000Network ManagerAuthor Commented:
Thanks everyone. I'm keeping this question active because I still need to test it.  Going to get to it today or tomorrow.
Thanks again for your help, all.
zito2000Network ManagerAuthor Commented:
Thank you for your help.

I used Qlemo's revision to Tom's original post and it worked like a charm!  Thank you both for the help with this!!

Have a great day!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.