在 asp.net mvc 中托管像 cli 这样的 powershell 来执行维护
我的 asp.net mvc 应用程序需要 CLI 来执行维护任务和一些状态任务。
我认为powershell就是为了提供CLI而设计的。但除了名字之外我一无所知。
如何在 iis 中运行的 asp.net mvc 中托管 powershell 来为自定义任务提供 CLI?
I need CLI for our asp.net mvc application to perform maintenance tasks and some status tasks.
I think powershell is designed to provide CLI. But i do not know anything about it other than name.
How can i host powershell in asp.net mvc running in iis to provide CLI for custom tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
托管和使用 PowerShell 引擎的 .NET 代码非常简单:
技巧在于配置 PowerShell 运行空间以限制可用命令。您可能不想允许某人从任何旧目录中删除文件、关闭计算机或格式化驱动器(他们可以访问路径中的 EXE)。查看受限运行空间来限制什么可以通过这个机制来执行。您还可以限制可用的语言功能。
The .NET code to host and use the PowerShell engine is very simple:
The trick is in configuring the PowerShell runspace to limit the available commands. You probably don't want to allow someone to delete files from any old directory, shutdown the computer or format a drive (they would have access to EXEs in the path). Look into Constrained Runspaces to limit what can be executed via this mechanism. You can also limit which language features are available.
我以前从未在 PowerShell 中使用过 CLI,但我以前在 .NET 应用程序中执行过一些 PowerShell 的优点。这可能会有所帮助。
本 Channel9 剧集包含在 .NET 应用程序中运行 PowerShell 2.0 命令的相关详细信息(比 1.0 容易得多):http://channel9.msdn.com/posts/bruceky/How-to-Embedding-PowerShell-Within-aC-Application/
(请注意,该过程不包括使用
System.Diagnostics.Process
在操作过程的标准输入和输出流时调用命令。遭遇挫折和失败。)I've never done CLI within PowerShell before, but I have executed some PowerShell goodness within a .NET application before. Here's something that might help.
This Channel9 episode contains relevant details for running PowerShell 2.0 commands in a .NET application (which is a lot easier than 1.0): http://channel9.msdn.com/posts/bruceky/How-to-Embedding-PowerShell-Within-a-C-Application/
(Note that the process does not include using
System.Diagnostics.Process
to invoke the commands while manipulating the process' standard input and output stream. Any attempts I made down that road were met with frustration and failure.)