[PowerShell Utils] Create a list of virtual machines based on configuration read from a CSV file in Hyper-V
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的更多相关文章
- [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 ...
- 使用Powershell在Microsoft Azure中创建Virtual Machine
获取虚拟机镜像 PS C:\WINDOWS\system32> Get-AzureVMImage 仅获得虚拟机名 PS C:\WINDOWS\system32> (Get-AzureVMI ...
- [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 ...
- [Windows Azure] Load Balancing Virtual Machines
Load Balancing Virtual Machines All virtual machines that you create in Windows Azure can automatica ...
- [Windows Azure] Manage the Availability of Virtual Machines
Manage the Availability of Virtual Machines You can ensure the availability of your application by u ...
- PatentTips - Method for network interface sharing among multiple virtual machines
BACKGROUND Many computing systems include a network interface card (NIC) to provide for communicatio ...
- PatentTips - Transparent unification of virtual machines
BACKGROUND Virtualization technology enables a single host computer running a virtual machine monito ...
- PatentTips - Method to manage memory in a platform with virtual machines
BACKGROUND INFORMATION Various mechanisms exist for managing memory in a virtual machine environment ...
- 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 ...
随机推荐
- Swift map filter reduce 使用指南
转载:https://useyourloaf.com/blog/swift-guide-to-map-filter-reduce/ Using map, filter or reduce to ope ...
- csdn 音乐 怎么拦截 提交后的程序 csdn 栏目 音乐 csdn 添加 音乐
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha csdn 栏目 音乐 csdn 添加 音乐 ======= <embed src= ...
- [POJ1144]Network
来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...
- JAVA中的email正则表达式
说到正则表达式,网上有很多的通用的表达式,可是事实上说来,一般人的都 不愿意去拿来研究,就是拿来就直接用就行了.可是,事实上,可能有些时候,项目中或公司里的实际情况不一样,得要修改一下正则表达式的,根 ...
- STM32的CRC32 软件实现代码
对于STM32的32位CRC,如果假定它的一个主要目的是为了校验往内部FLASH存储数据的可靠性,那么(余数)初值是全1当然是比较合理的.由于STM32的32位CRC是纯32位,即每次必须输入32位的 ...
- muduo 的 shutdown() 没有直接关闭 TCP 连接?
http://blog.csdn.net/Solstice/article/details/6208634 今天收到一位网友来信: 在 simple 中的 daytime 示例中,服务端主动关闭时调用 ...
- .NET开源作业调度框架(Quartz.NET和FluentScheduler)实战项目演练
一.课程介绍 明人不说暗话,跟着阿笨一起玩NET .本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的一部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高级编程的技巧分享 ...
- ASP.NET MVC中检测浏览器版本并提示下载更新
如果网站使用html5.css3.自适应等新特性,可能有些浏览器版本不支持.这时候,需要提醒浏览者更新浏览器的版本到最新. 本篇用到的插件为:http://jreject.turnwheel.com/ ...
- Delphi 获取命令行输出的函数
function GetDosOutput(CommandLine: string; Work: string = 'C:\'): string; var SA: TSecurityAttribute ...
- delphi时间日期函数
unit DateProcess; interface const DayOfWeekStrings: ..] of String = ('SUNDAY', 'MONDAY', 'TUESDAY', ...