Save Exchange PowerShell Command

zito2000
zito2000 used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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/
AmitIT Architect
Distinguished Expert 2017

Commented:
Copy/paste in notepad first and then save it as .ps1.
zito2000Network Manager

Author

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"
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

AmitIT Architect
Distinguished Expert 2017

Commented:
You need to call the Exchange snap-in in  your command.
Tom CieslikIT Engineer
Distinguished Expert 2017

Commented:
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 Manager

Author

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

Commented:
Follow the attached document for powershell remoting into exchange :- https://technet.microsoft.com/en-us/library/dd335083(v=exchg.160).aspx
IT Engineer
Distinguished Expert 2017
Commented:
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
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
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 Architect
Distinguished Expert 2017

Commented:
Try out Tom advise above.
zito2000Network Manager

Author

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 Manager

Author

Commented:
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!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial