Hello everyone, this is the third post of the series. .

 

Background

===============

In my solution, I have 15 Windows hosts. I need to configure them from the OS installation to configure fail over cluster and then create and run VMs on them. Without scripting, manually complete related tasks would be very bored and easy to make mistakes. I started using PowerShell and it really helped ease the pain.

 

What can this one do

===============

I need to create about 20 VMs, they have different settings, such as number of CPU, Memory amount, Virtual Disk Size, Location, etc. I don’t want to mannually configure them all in GUI. So…

This script will read a CSV file, and get the configuration for each VM, and then automatically create all the VMs based on your requirement.

As always, everything in one click!

 

Logic Intro

===============

Nothing special, just read CSV and create VMs one after another.

The hard part is the usage of each of the cmdlet involved. Took me most of the time.

Note the (Invoke-Expression $vairable.member), this is special.

 

Script is here

===============

$b = Import-Csv D:\XYZABC\CreateVMs.csv -Header VMName, Processor, RAM, VHDSize, VMLocation, VirtualSwtich

Foreach ( $vm in $b )
{
New-Item -Path $vm.VMLocation -ItemType directory -force -ErrorAction SilentlyContinue
New-VM $vm.VMName -path $vm.VMLocation
New-VHD -Path ("{0}/{1}/{1}.vhdx" -f $vm.VMLocation, $vm.VMName) -SizeBytes (Invoke-Expression $vm.VHDSize)
Add-VMHardDiskDrive -VMName $vm.VMName -ControllerType SCSI -ControllerNumber 0 -path ("{0}/{1}/{1}.vhdx" -f $vm.VMLocation, $vm.VMName)
Get-VM $vm.VMName | Set-VMMemory -DynamicMemoryEnabled 0 -StartupBytes (Invoke-Expression $vm.RAM)
Get-VM $vm.VMName | Set-VMProcessor -count $vm.Processor
Get-VM $vm.VMName | Add-VMNetworkAdapter -SwitchName $vm.VirtualSwtich
}

This is what the CSV look like.

 

Further

============

I know SCVMM should be better at this task. I will learn it, and post update on this topic as soon as I tuned how to make SCVMM able to do the same thing on a windows failover cluster.

 

Please forgive me for not listing all the articles that supported me on writing out this script. There are so many… …

[PowerShell Utils] Create a list of virtual machines based on configuration read from a CSV file in Hyper-V的更多相关文章

  1. [SQL in Azure] Getting Started with SQL Server in Azure Virtual Machines

    This topic provides guidelines on how to sign up for SQL Server on a Azure virtual machine and how t ...

  2. 使用Powershell在Microsoft Azure中创建Virtual Machine

    获取虚拟机镜像 PS C:\WINDOWS\system32> Get-AzureVMImage 仅获得虚拟机名 PS C:\WINDOWS\system32> (Get-AzureVMI ...

  3. [SQL in Azure] High Availability and Disaster Recovery for SQL Server in Azure Virtual Machines

    http://msdn.microsoft.com/en-us/library/azure/jj870962.aspx Microsoft Azure virtual machines (VMs) w ...

  4. [Windows Azure] Load Balancing Virtual Machines

    Load Balancing Virtual Machines All virtual machines that you create in Windows Azure can automatica ...

  5. [Windows Azure] Manage the Availability of Virtual Machines

    Manage the Availability of Virtual Machines You can ensure the availability of your application by u ...

  6. PatentTips - Method for network interface sharing among multiple virtual machines

    BACKGROUND Many computing systems include a network interface card (NIC) to provide for communicatio ...

  7. PatentTips - Transparent unification of virtual machines

    BACKGROUND Virtualization technology enables a single host computer running a virtual machine monito ...

  8. PatentTips - Method to manage memory in a platform with virtual machines

    BACKGROUND INFORMATION Various mechanisms exist for managing memory in a virtual machine environment ...

  9. Microsoft server software support for Microsoft Azure virtual machines

    http://support.microsoft.com/kb/2721672/en-us  Article ID: 2721672 - Last Review: November 22, 2014 ...

随机推荐

  1. Nessus漏洞扫描教程之安装Nessus工具

    Nessus漏洞扫描教程之安装Nessus工具 Nessus基础知识 Nessus号称是世界上最流行的漏洞扫描程序,全世界有超过75000个组织在使用它.该工具提供完整的电脑漏洞扫描服务,并随时更新其 ...

  2. Prim算法和Kruskal算法

       Prim算法和Kruskal算法都能从连通图找出最小生成树.区别在于Prim算法是以某个顶点出发挨个找,而Kruskal是先排序边,每次选出最短距离的边再找. 一.Prim(普里姆算法)算法: ...

  3. hdu 2710 水题

    题意:判断一些数里有最大因子的数 水题,省赛即将临近,高效的代码风格需要养成,为了简化代码,以后可能会更多的使用宏定义,但是通常也只是快速拿下第一道水题,涨自信.大部分的代码还是普通的形式,实际上能简 ...

  4. BZOJ4239 : 巴士走读

    考虑按时刻从早到晚模拟,计算出 f[i]:到达i点的最晚出发时间 g[i]:为了赶上第i辆车的最晚出发时间 然后将所有到达n号点的巴士按到达时间排序,查询的时候二分查找即可. 时间复杂度$O(n\lo ...

  5. 简单的抖动运动 主要利用offset left 和 setTimeout

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. HDU 4813 Hard Code(水题,2013年长春现场赛A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4813 签到题. 把一个字符串按照格式输出就可以了,很水 #include <stdio.h> ...

  7. JS本地存储信息的实现方式(localStorage 与 userData)

    详细介绍请看: http://www.cnblogs.com/beiyuu/archive/2011/07/20/js-localstorage-userdata.html 里面涉及到的 demo 代 ...

  8. 两次被百度k站两次恢复的亲身经历

    最后,网站被k了并不是最重要的,最重要的是你能不能找到网站被k的病因所在,不知道病因的话,就盲目的优化,恢复起来可能效果就不太明显,也比较浪费时间.只有找到了被k的原因,这样恢复起来才会得心应手,省时 ...

  9. 再谈vc发送键盘、组合键消息

    关于向Windows窗口发送Alt组合键的问题,这个真是经典问题啊,在网上找了一下,问的人N多,方法差不多, 但就是没有很好解决问题. 之前找到一个能正确发送的code:(Alt+A) PostMes ...

  10. Property's synthesized getter follows Cocoa naming convention for returning

    Property's synthesized getter follows Cocoa naming convention for returning.   今天早上在整理代码的时候发现了如上警告. ...