Calling Powershell Cmdlets from Cmd Prompt
We have been creating an application for Exchange 2007 that will be shipped to our customer. There are certain aspects of the installation that we would like to take care of via a batch file. I was wondering if it is possible to call powershell commands such as: Set-TransportServer SERVER -RootDropDirectoryPath "C:\Messages" Set-ForeignConnector "SERVER Connector" -DropDirectory "Msg" I know the call powershell.exe can be made from the command line. The downside to this is thatthere are alimited number of commands. Is it possible to use these (Set-TransportServerand Set-ForeignConnector)powerhsell cmdlets from a cmd prompt batch file and how would this be done? Is thereanothermanner in which this could occur? Is this something that can only be done through the Exchange Management System?
January 12th, 2007 4:36pm

Hi,I haven't tested this but I think it's likely to work.Add the following to your batch file:C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1# Add your PowerShell or EMShell commands here.#'"Very possibly you will want to omit the -NoExit parameter when you go live. I left it in the above so you can demonstrate that the Exchange Management Shell starts with the command and, once you add other PowerShell or Exchange Management Shell commands, you can demonstrate (I hope) that they work.I hope that helps.
Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2007 2:19am

This did notwork for me. What I did get to work was making a copy of Exhchange.ps1,adding the cmdlets that I want to run at the end of the file, and running your command again.
January 24th, 2007 11:06pm

Hi,The approach I suggested does work - I just tested it, but I had the syntax marginally wrong.The following syntax works:C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\bin\Exchange.ps1'; #Add your PowerShell or EMShell commands here separated by semicolons.#"
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2007 5:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics