Sachin Filinto Blog Executing Exchange PowerShell commands from a CMD Prompt - Random Technical Artices By Sachin Filinto - Site Home - TechNet Blogs

Random Technical Artices By Sachin Filinto

Random Technical Artices By Sachin Filinto

Executing Exchange PowerShell commands from a CMD Prompt

Executing Exchange PowerShell commands from a CMD Prompt

  • Comments 5
  • Likes

A Quick blog on how to execute an Exchange PowerShell script (.ps1 extension) from a command prompt.

A .ps1 cannot be executed from a Command prompt. to execute it one needs to use a PowerShell shell. Further if this script calls any exchange cmdlet, it would require to be executed in an Exchange Management Shell.

 

The following command does all three in one line. i.e. run the script from c:\script\script.ps1 ( which is an exchange script ) from a command prompt.

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psconsolefile "C:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1" -file "C:\script\script.ps1"

Comments
  • Today I used this to run some command. Good Info. Thanks.

  • Very helpful in troubleshooting. Thank you.

  • Awesome. I have spent an hour reading some comples crap about PSSession and so on, but this is a real solution!

  • How do you pass parameters into the PS1 script that you have in -file?

    -file "C:\script\script.ps1" need to pass -parameter1 -parameter2 $false

  • Thank you! This mixed with PDQ deploy. I have what I need to automate some tedious tasks the business wants done.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment