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
     
     
  • 相关阅读:
    REVERSE!REVERSE!REVERSE!
    java和数据结构的面试考点
    39. recover rotated sorted array恢复旋转排序数组
    33. Search in Rotated Sorted Array旋转数组二分法查询
    搜索旋转排序数组 II
    Eclipse 查找
    在Java中返回多个值
    Java的标识符
    fwprintf (File input/output) – C 中文开发手册
    CSS盒子模型介绍 | CSS Box Model: Introduction to the CSS box model (Miscellaneous Level 1) – CSS 中文开发手册
  • 原文地址:https://www.cnblogs.com/net2012/p/2881296.html
Copyright © 2011-2022 走看看