从 Visual Basic/C#/.NET 应用程序运行 Exchange Management Shell cmdlet
目标:使用 Visual Basic、C# 或 .NET 提供与 Exchange 命令行管理程序交互的 Web 服务,向其发送命令以运行 cmdlet,并以 XML 形式返回结果。 (请注意,我们可以使用任何语言来编写服务,但由于它是 Windows Box 并且我们有 Visual Studio 2008,因此似乎最简单的解决方案就是使用它来创建 VB/.NET Web 服务。事实上,它这样做非常容易,只需点击即可。)
问题:如何从 Web 服务运行 Exchange Management Shell cmdlet,例如 Get-DistributionGroupMember“Live Presidents”
似乎我们应该能够创建一个运行的 PowerShell 脚本cmdlet,并且能够从命令行调用它,因此只需从程序内调用它。这听起来正确吗?如果是这样我该怎么办?谢谢。答案可能与语言无关,但 Visual Basic 可能是最好的,因为我就是在其中加载测试 Web 服务的。
Goal: Provide a web service using Visual Basic or C# or .NET that interacts with the Exchange Management Shell, sending it commands to run cmdlets, and return the results as XML. (Note that we could use any lanaguage to write the service, but since it is a Windows Box and we have Visual Studio 2008, it seemed like easiest solution would be just use it to create a VB/.NET web service. Indeed, it was quite easy to do so, just point and click.)
Problem: How to run an Exchange Management Shell cmdlet from the web service, e.g, Get-DistributionGroupMember "Live Presidents"
Seems that we should be able to create a PowerShell script that runs the cmdlet, and be able to call that from the command line, and thus just call it from within the program. Does this sound correct? If so how would I go about this? Thanks. Answer can be language agnostic, but Visual Basic would probably be best since that is what I loaded the test web service up in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际代码改编自MSDN http:// /msdn.microsoft.com/en-us/library/exchange/bb332449(v=exchg.80).aspx 可能很棘手,因为您必须获得正确的权限并在具有所有权限的计算机上运行它交换插件:
The actual code adapted from from MSDN http://msdn.microsoft.com/en-us/library/exchange/bb332449(v=exchg.80).aspx can be tricky because you have to get the permissions right and run it on a macine with all of the Exchange plug-ins:
好吧,虽然没有得到答案,但大概明白了。我在运行 64 位 PowerShell 时遇到问题,但最终升级到 Exchange 2010 并使用 C#,然后就不再有问题了。
简而言之,您在 Visual Studio 中创建一个新的 PowerShell 应用程序,然后添加对 System.Management.Automation dll 的引用。这允许您为 Powershell 设置命名空间并对其进行调用。 http://msdn.microsoft.com /en-us/library/system.management.automation(VS.85).aspx 使用可用的 Pipeline 类创建 Pipeline http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces .pipeline(VS.85).aspx 以便通过管道传回您的命令。然后输入命令,如果需要的话添加参数。运行该应用程序,它将返回您在 PowerShell 中调用的 cmdlet 的结果,您可以从那里开始。
Well, didn't get an answer, but sort of figured it out. I had a problem getting a 64-bit PowerShell to run, but eventually upgraded to Exchange 2010 and used C# and then there was no longer a problem.
The short answer is that you create a new PowerShell application in Visual Studio, then you add a reference to the System.Management.Automation dll. This allows you to set up a namespace for Powershell and make calls to it. http://msdn.microsoft.com/en-us/library/system.management.automation(VS.85).aspx You create a Pipeline using the available Pipeline class http://msdn.microsoft.com/en-us/library/system.management.automation.runspaces.pipeline(VS.85).aspx in order to pipe your commands back. Then you put your commands in, add parameters if needed. Run the app and it will return the results from the cmdlets you called in the PowerShell and you can go from there.