Category Archives: Run

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.
eg:
powershell –command  “. ‘c:maintenancetuesday.ps1′”
To load a custom powershell console, for example the Exchange Management Shell, use the following:
powershell –PSConsoleFile %PSC1% –command “. ‘%SCRIPT%'”
eg:
powershell –PSConsoleFile “c:program filesmicrosoftexchange serverv14binExSchell.psc1” -Command “. ‘c:maintenanceReportMailboxSizeExchange2010.ps1′”