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!
zito2000Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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. 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: https://www.howtogeek.com/204088/how-to-use-a-batch-file-to-make-powershell-scripts-easier-to-run/
0
AmitIT ArchitectCommented:
Copy/paste in notepad first and then save it as .ps1.
0
zito2000Author 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"
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

AmitIT ArchitectCommented:
You need to call the Exchange snap-in in  your command.
0
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
0
zito2000Author 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
0
Mohammad Ishtyaq khatriSr. EngineerCommented:
Follow the attached document for powershell remoting into exchange :- https://technet.microsoft.com/en-us/library/dd335083(v=exchg.160).aspx
0
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
0

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

1
AmitIT ArchitectCommented:
Try out Tom advise above.
0
zito2000Author 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.
0
zito2000Author 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!
0
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
Powershell

From novice to tech pro — start learning today.