首先,将要执行的EMS命令写入ps1脚本中,即用记事本工具编写EMS命令,然后将该文件保存为一个“*.ps1”文件。如:编写“get-mailbox”,保存到“c:\ems.ps1”中。

然后,使用记事本建立一个bat内容如下:
 
 
powershell.exe -PSconsoleFile "c:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1" -Command ".'c:\ ems.ps1'"
 
如果PS1脚本需要携带参数,按照如下执行
powershell.exe -PSconsoleFile "c:\Program Files\Microsoft\Exchange Server\V14\Bin\exshell.psc1" -Command " .'d:\ps_bat\import.ps1'" -all
 
-ALL是参数
 
 
保存为“runems.bat”。注:Exchange 2010按默认安装在C盘默认路径。
 
 
BAT可以直接执行,也可以在“任务计划”中进行计划执行