Thursday, January 16, 2014

Run multiple .PS1 scripts when launching PowerShell

  • In the "-command" argument block, a semicolon is an end-of-line delimiter, similar to C#
  • Each line in the "-command" argument block is executed as if it were typed inside the PowerShell interface

Full command to load the Exchange console plus an additional script:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer cas.companyname.com;Set-AdServerSettings -ViewEntireForest $True; C:\custom\scripts\Script2.ps1"

References
Scripting with the Exchange Management Shell
http://technet.microsoft.com/en-us/library/bb123798%28v=exchg.150%29.aspx#RunScript