Link to home
Start Free TrialLog in
Avatar of zito2000
zito2000Flag for United States of America

asked on

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!
Avatar of Mohammad Ishtyaq khatri
Mohammad Ishtyaq khatri
Flag of United States of America image

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: https://www.howtogeek.com/204088/how-to-use-a-batch-file-to-make-powershell-scripts-easier-to-run/
Copy/paste in notepad first and then save it as .ps1.
Avatar of zito2000

ASKER

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"
You need to call the Exchange snap-in in  your command.
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
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
Follow the attached document for powershell remoting into exchange :- https://technet.microsoft.com/en-us/library/dd335083(v=exchg.160).aspx
ASKER CERTIFIED SOLUTION
Avatar of Tom Cieslik
Tom Cieslik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try out Tom advise above.
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.
Tom/Qlemo,
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!