[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 ...
随机推荐
- Xtreme8.0 - Sum it up 水题
Sum it up 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/sum-it-up Descr ...
- hdu 5726 GCD 暴力倍增rmq
GCD/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5726 Description Give you a sequence ...
- Slickflow.NET 开源工作流引擎基础介绍(九) -- .NET Core2.0 版本实现介绍
前言:.NET Core 是.NET Framework的新一代版本,是微软开发的第一个跨平台 (Windows.Mac OSX.Linux) 的应用程序开发框架(Application Framew ...
- 针对MyISAM锁表的解决方案
最近服务器上经常出现mysql进程占CPU100%的情况,使用show processlist命令后,看到出现了很多状态为LOCKED的sql.使用show status like 'table%'检 ...
- 12174 - Shuffle
这道题能够用"滑动窗体"的思想来做,假想一个滑动的窗体,这个窗体的大小是s.划过一个大小为n的区域,可是由于s可能比n大,所以我们最好还是不去考虑s和n的大小,直接开出一个足够大的 ...
- ARM JTAG 20P to Cortex JTAG 10P
- ISO 7816-4: Annex A: Transportation of APDU messages by T=0
http://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-4_annex-a.aspx Annex A: Transportation ...
- 【Go命令教程】1. 标准命令详解
Go 语言的 1.5 版本在标准命令方面有了重大变更.这倒不是说它们的用法有多大的变化,而是说它们的底层支持已经大变样了.让我们先来对比一下 $GOROOT/pkg/tool/< 平台相关目录 ...
- DNS服务器
DNS服务器是指“域名解析服务器”,而域名就是我们通常所说的“网址”.在互联网中识别和寻找不同的计算机,实际上是需要知道该计算机的IP地址才能进行访问.比如220.181.38.4,这个IP就是百度的 ...
- 【java】java下载文件中换行符 在windows和linux下通用的
请使用: public static final String FILE_CONTENT_SPLIT_MARK = "\r\n"; 注意 不是"\n\r",顺序 ...