如何在批处理文件中使用Exchange 2010 cmdlet

时间:2011-11-25 06:47:14

标签: cmd exchange-server cmdlets

我可以直接在Exchange命令行管理程序中正确运行Get-ActiveSyncDeviceAccessRule。 (参考:http://technet.microsoft.com/en-us/library/dd776124.aspx

然后我写了一个批处理文件,如下所示,但我得到CommandNotFoundException。我想知道如何在cmd.exe中使用此cmdlet?任何人都可以帮助我吗?谢谢。

(编者注:接下来的三行是为格式化而包装的。原来是1行)

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  Get-ActiveSyncDeviceAccessRule >C:\ActiveSyncDeviceAccessRule_output.txt
  2>C:\standardError.txt
echo %errorlevel% >C:\exitCode.txt

我在standardError.txt中收到如下错误:

The term 'Get-ActiveSyncDeviceAccessRule' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:31
+ Get-ActiveSyncDeviceAccessRule <<<< 
    + CategoryInfo          : ObjectNotFound: (Get-ActiveSyncDeviceAccessRule: 
   String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

1 个答案:

答案 0 :(得分:1)

(OP在问题编辑中回答。转换为社区Wiki答案。见Question with no answers, but issue solved in the comments (or extended in chat)

OP写道:

  

我解决了我的问题。我错过了一些连接Exchange服务器的命令。 cmdlet Get-ActiveSyncDeviceAccessRule属于Exchange Server 2010 SP1。您可以在Exchange命令行管理程序的属性窗口中找到目标命令。

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 
'C:\Program    Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1';
Connect-ExchangeServer -auto"
  

我更新了我的批处理文件,如下所示。它有效。

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 
'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; 
Connect-ExchangeServer -auto;Get-ActiveSyncDeviceAccessRule" 
>C:\ActiveSyncDeviceAccessRule_output.txt 2>C:\standardError.txt
echo %errorlevel% >C:\exitCode.txt