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. UML类图-聚合和组合的区别

    类图-组合和聚合 学习自 http://blog.sina.com.cn/s/blog_4ae8f77f0100ji5k.html http://blog.csdn.net/nodeathphoeni ...

  2. Lambda的分类(语句Lambda和表达式Lambda)

    学习自 <C#本质论> Overview 在上一文中,我们简而又简的了解了一下,匿名方法和Lambda表达式,关于匿名方法这里暂且不表,本文我们来更加详细的了解一下Lambda表达式. 本 ...

  3. GBDT算法

    GBDT通过多轮迭代,每轮迭代产生一个弱分类器,其中弱分类器通常选择为CART树,每个分类器在上一轮分类器的残差基础上进行训练. 对于GBDT算法,其中重要的知识点为: 1.GBDT是梯度下降法从参数 ...

  4. hdu 4432 第37届ACM/ICPC天津现场赛B题

    题目大意就是找出n的约数,然后把约数在m进制下展开,各个数位的每一位平方求和,然后按m进制输出. 模拟即可 #include<cstdio> #include<iostream> ...

  5. lvs+keepalived 02

    LVS keepalived 高可用负载均衡 环境 IP HOSTNAME Describe 192.168.100.30 lvs01 主负载 192.168.100.31 lvs02 备负载 192 ...

  6. Temporary ASP.Net Files探究

    了解.net平台的兄弟都知道,.net也是采用动态编译的也就是说我们常说的build生成的dll只是中间代码而在web第一次请求的时候才是真正意义上的编译生成二进制代码这也就是为什么刚编译完第一次打开 ...

  7. 计算机意外地重新启动或遇到错误。windows安装无法继续。若要安装windows 请单击 确定 重新启动计算机

    快安装完系统时遇到提示:计算机意外地重新启动或遇到错误.Windows 安装无法继续.若要安装Windows,请单击“确定”重新启动计算机,然后重新启动安装”.如下图所示: 解决办法: 当出现如上提示 ...

  8. 在ASP.NET MVC中使用Knockout实践03,巧用data参数

    使用Knockout,当通过构造函数创建View Model的时候,构造函数的参数个数很可能是不确定的,于是就有了这样的一个解决方案:向构造函数传递一个object类型的参数data. <inp ...

  9. AutoMapper在MVC中的运用05-映射中的忽略、处理null、多种映射转换

    本篇AutoMapper使用场景: ※ 动态实现接口方法或属性 ※ 目标中的属性如果比源多,可以忽略多出的属性 ※ 目标有virtual属性,可忽略 ※ 目标属性值为null的解决办法 ※ int转s ...

  10. [转]过XX游戏驱动保护的代码

    这个是过TX游戏自我保护驱动的源代码.可以过qq堂.DNF.寻仙等QQ游戏. #include <ntddk.h>#include <windef.h>#include < ...