2

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

然后我写了一个批处理文件,如下所示,但我得到了CommandNotFoundException. 我想知道如何将此 cmdlet 与 cmd.exe 一起使用?谁能帮助我?谢谢你。

(编者注:接下来的三行是为了格式化而换行的。原来是 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
4

1 回答 1

1

(由 OP 在问题编辑中回答。转换为社区 Wiki 答案。请参阅没有答案的问题,但问题在评论中解决(或在聊天中扩展)

OP写道:

我已经解决了我的问题。我错过了一些连接 Exchange 服务器的命令。该 cmdletGet-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
于 2015-01-29T12:09:49.937 回答