Saturday, October 12, 2013

Run a Powershell script (.ps1) from command line

To run a Powershell script from the command line, batch file or task scheduler, use the following:
powershell -command ". '%SCRIPT%'"
Note the double quotes (“) followed by single quotes (‘), and the reverse on the end of the line.
powershell –command  ". 'c:\maintenance\tuesday.ps1'"
To load a custom powershell console, for example the Exchange Management Shell, use the following:
powershell –PSConsoleFile %PSC1% –command ". '%SCRIPT%'"
powershell –PSConsoleFile "c:\program files\microsoft\exchange server\v14\bin\ExSchell.psc1" -Command ". 'c:\maintenance\ReportMailboxSizeExchange2010.ps1'"

No comments:

Post a Comment