zoukankan      html  css  js  c++  java
  • C#调PowerShell在SCVMM中创建虚拟机时,实时显示创建进度 天高地厚

    环境:

      Win server 2008 R2 + Hyper-v + SCVMM2008 R2

    目的:

      C#调PowerShell在SCVMM中创建虚拟机时,实时显示创建进度

    在SCVMM2008R2中手动创建一个vm(虚拟机)时,作业界面中会显示很详细的创建进度,包括有哪些子任务,每个任务的完成度、状态等信息。SCVMM的界面操作是基于Powershell的,所以肯定有ps脚本可以实现上述目的。

    microsoft提供的创建虚拟机的ps脚本中,提到如下内容(为显示PS脚本中部分内容被回车

    $NewVMTasks= [System.Array]::CreateInstance("Microsoft.SystemCenter.VirtualMachineManager.Task", $NumVMs)
    $NewVMs= [System.Array]::CreateInstance("Microsoft.SystemCenter.VirtualMachineManager.VM", $NumVMs)
    $i=0
    # Loop that creates each VM asynchronously.
    while($NumVMs-gt0)
    {
    # Generate a unique VM name.
    $VMRnd=$Random.next()
    $NewVMName=$VMName+$VMRnd
    # Get the ratings for each host and sort the hosts by ratings.
    $Ratings=@(Get-VMHostRating -Template $Template-VMHost $VMHosts-DiskSpaceGB $DiskSizeGB
     -VMName $NewVMName| where { $_.Rating -gt0} | Sort-Object -property Rating -descending)
    if ($Ratings.Count -gt0)
    {
    $VMHost=$Ratings[0].VMHost
    $VMPath=$Ratings[0].VMHost.VMPaths[0]
    # Create a new VM from the template and add an additional VHD
    # to the VM.
    $NewVMJobGroup= [System.Guid]::NewGuid()
    $VMAdditionalVhd| Add-VirtualHardDisk -Bus 0-Lun 1-IDE -JobGroup $NewVMJobGroup
    $NewVMs
     
     
  • 相关阅读:
    Kubernetes豁然贯通(安全认证)
    Kubernetes登堂入室(数据存储)
    Kubernetes渐入佳境(Service和Ingress详解)
    Kubernetes崭露头角(Pod控制器详解)
    Kubernetes初露锋芒(Pod详解)
    Kubernets初窥门径 (NameSpace、Pod、Label、Deployment、Service)
    Kubernetes初学乍练(资源管理)
    Kubernetes小试牛刀
    构建高并发的扣减服务
    Redis集群的三种姿势
  • 原文地址:https://www.cnblogs.com/net2012/p/2881296.html
Copyright © 2011-2022 走看看