如何在 VB.Net 中运行 Powershell 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11782121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run Powershell scripts in VB.Net
提问by Pickle
I need to run an Exchange 2007 powershell script in VB.Net, but I can't seem to find a method that shows how to do it with the module loaded.
我需要在 VB.Net 中运行 Exchange 2007 powershell 脚本,但我似乎无法找到一种方法来显示如何在加载模块的情况下执行此操作。
What is the best method to do this?
执行此操作的最佳方法是什么?
回答by Dayan
You can run powershell scripts in VB, take a look at the following link
你可以在VB中运行powershell脚本,看看下面的链接
The link posted above takes you step by step on how to accomplish this.
上面发布的链接将带您逐步了解如何完成此操作。
Check out this question that relates to yours:Running powershell scripts from within a .NET windows app
查看与您相关的问题:Running powershell scripts from within a .NET windows app
This following article is in C# but should help you understand the concept a bit better:
下面这篇文章是用 C# 编写的,但应该可以帮助您更好地理解这个概念:
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
回答by Nick Roche-Kerr
For VB.NET try this code:
对于 VB.NET,试试这个代码:
Process.Start("powershell", "-File C:\YourFileLocation")
Basically, all you're doing is calling PowerShell and specifying an argument (the location of the cmdlet you're calling).
基本上,您所做的就是调用 PowerShell 并指定一个参数(您正在调用的 cmdlet 的位置)。