Asp.net使用powershell管理hyper-v
2015-11-02 21:09
555 查看
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.Collections.ObjectModel; using System.Text; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { RunspaceConfiguration rconfig = RunspaceConfiguration.Create(); PSSnapInException Pwarn = new PSSnapInException(); Runspace runspace = RunspaceFactory.CreateRunspace(); string test = "Import-Module VirtualMachineManager\r\n"; runspace = RunspaceFactory.CreateRunspace(rconfig); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(test); try { var results = pipeline.Invoke(); using (Pipeline pipe = runspace.CreatePipeline()) { //Start-VM -name XXXXX Command cmd = new Command("Start-VM"); cmd.Parameters.Add("Name", "test_machine2"); pipe.Commands.Add(cmd); var result = pipe.Invoke(); Label1.Text = results.ToString(); } } catch (Exception ex) { throw ex; Label1.Text = ex.ToString(); } } }
相关文章推荐
- SHELL脚本 数学运算、数组、文本处理
- C/C++ ShellExecuteEx调用exe可执行文件
- C/C++ ShellExecuteEx调用exe可执行文件
- SHELL脚本基础
- 手把手教你写shell脚本——shell循环结构
- C#调用PowerShell脚本
- Win32中调用其他应用程序的方法(函数)winexec,shellexecute ,createprocess
- 51nod 1070 Bash游戏 V4 (博弈论_找规律)
- PowerShell入门(一):PowerShell能干什么?
- shell 使用printf
- shell script 之test
- 希尔排序
- PowerShell入门(序):为什么需要PowerShell?
- 认识与学习shell
- Javaweb架构分析安全之万户ezoffice全版本通杀上传GETSHELL
- shell 命令行的学习
- linux基础 --- shell
- 通过PowerShell 脚本在中国区Azure部署定制化HDInsight 集群
- shell script 学习笔记-----命令执行
- 编译android出现 /bin/bash: jar: command not found; /bin/bash: javah: command not found解决办法