博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Asp.net使用powershell管理hyper-v
阅读量:6950 次
发布时间:2019-06-27

本文共 1493 字,大约阅读时间需要 4 分钟。

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();        }    }}

 

转载于:https://www.cnblogs.com/wicrecend/p/4931397.html

你可能感兴趣的文章
Android创建和使用数据库
查看>>
25、Python之禅
查看>>
YOLOv3的Darknet在OpenCV3.4.1(bug)下编译出错填坑
查看>>
有意义的命名
查看>>
POJ——3517
查看>>
POJ 2886
查看>>
shiro登录步骤源码分析
查看>>
Java进阶篇(二)——抽象类、内部类
查看>>
将Redis设置为后台启动
查看>>
为自己的博客园添加右侧目录
查看>>
TypeScript 学习二 表达式和循环
查看>>
CentOS 6.5安装部署Zabbix监控系统
查看>>
Sql server 2008 R2 导出/导入数据报错之无法打开全局共享内存以与性能 DLL 通信
查看>>
*#06# 新购手机 指令测试
查看>>
Microsoft Lookback Adapter添加并设置回环网卡(转)
查看>>
android点滴(24)之android 创建、删除、判断是否存在快捷方式
查看>>
iOS怎么给颜色设置透明度?
查看>>
开源GIT仓库-----gogs
查看>>
openal-soft
查看>>
数据绑定介绍
查看>>