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

发布于 2024-12-18 02:58:54 字数 1156 浏览 1 评论 0原文

我可以直接在 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

I can run Get-ActiveSyncDeviceAccessRule correctly in Exchange Management Shell directly.
(reference: http://technet.microsoft.com/en-us/library/dd776124.aspx)

Then I wrote a batch file as below, but I got CommandNotFoundException. I'd like to know how I can use this cmdlet with cmd.exe? Could anyone can help me? Thank you.

(Editor's note: The next three lines were wrapped for formatting. Originally 1 line)

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

And I get error in standardError.txt as below:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2024-12-25 02:58:54

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

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

(Answered by the OP in a question edit. Converted to a community Wiki Answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

I've solved my problem. I missed some command to connect the Exchange server. And the cmdlet Get-ActiveSyncDeviceAccessRuleis belong to Exchange Server 2010 SP1. You can find the target command in the properties window of Exchange Management Shell.

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

I updated my batch file as below. And it works.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文