问题描述
我可以直接在Exchange命令行管理程序中正确运行Get-ActiveSyncDeviceAccessRule。
(参考:)
然后我写了一个批处理文件如下,但我得到 CommandNotFoundException
。我想知道如何可以使用cmdlet cmd.exe?有人可以帮助我吗?非常感谢。
(编辑注:下面三行是格式化的,原来是一行)
C:\Windows\System32\WowPowerShell\v1.0\powershell.exe
Get-ActiveSyncDeviceAccessRule> C:\ActiveSyncDeviceAccessRule_output.txt
2> C:\standardError.txt
echo%errorlevel%> C:\exitCode.txt
我在 standardError.txt
中出现错误,如下所示:
术语'Get-ActiveSyncDeviceAccessRule'不被识别为
cmdlet,函数,脚本文件或可操作程序的名称。检查
名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
at line:1 char:31
+ Get-ActiveSyncDeviceAccessRule<<<
+ CategoryInfo:ObjectNotFound:(Get-ActiveSyncDeviceAccessRule:
String)[],CommandNotFoundException
+ FullyQualifiedErrorId:CommandNotFoundException
解决方案(在一个问题编辑中由OP回答)转换到社区Wiki答案见)
OP写道:
C: \\ Windows \System32 \WindowsPowerShell\v1.0\powershell.exe命令。
'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
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
解决方案(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 )
The OP wrote:
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
这篇关于如何在批处理文件中使用Exchange 2010 cmdlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!