-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-labvm.ps1
48 lines (43 loc) · 1.29 KB
/
new-labvm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Requires -RunAsAdministrator
#Requires -Modules Hyper-v
<#
.Synopsis
Create VMs using differencing VHDs for lab purposes
.DESCRIPTION
Create new Hyper-V machines, based on a sysprepped, ready VHD to quickly spawn multiple VMs for lab purposes.
.EXAMPLE
import-csv "machines.csv" | .\new-labvm.ps1 | start-vm
Using the default CSV-template, you create the VMs and inmediatly boot them up.
.EXAMPLE
.\new-labvm.ps1 -VMName <string[]>
.\new-labvm.ps1 -VMName bob,jef,lilly
Creates 3 VM's, named bob, jef and lilly with default values
#>
[CMDLETBinding()]
param(
[Parameter(Mandatory=$true,
Valuefrompipeline=$True,
Valuefrompipelinebypropertyname=$true
)]
[string[]]$VMName,
[Parameter(Mandatory=$false,
Valuefrompipeline=$true,
Valuefrompipelinebypropertyname=$true
)]
[string]$Sourcepath="E:\vms\Differentialclient\Differntialclient\Virtual Hard Disks\Differntialclient.vhdx",
[Parameter(Mandatory=$false,
Valuefrompipeline=$true,
Valuefrompipelinebypropertyname=$true
)]
[string]$Memory="2048MB"
)
BEGIN{
}
PROCESS{
foreach($VM in $VMName)
{
$NewVHD= new-vhd -ParentPath $SourcePath -path E:\vms\$VM.vhdx -Differencing
$NewVM = New-VM -Name "$VM" -VHDPath "E:\vms\$VM.vhdx" -MemoryStartupBytes 2048MB
}
}
END{}