-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathNew-LabVM.ps1
More file actions
65 lines (51 loc) · 1.96 KB
/
New-LabVM.ps1
File metadata and controls
65 lines (51 loc) · 1.96 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
__ __ ______ ______ ______
/ | / |/ | / \ / \
$$ | /$$/ $$$$$$/ /$$$$$$ |/$$$$$$ |
$$ |/$$/ $$ | $$ \__$$/ $$ \__$$/
$$ $$< $$ | $$ \ $$ \
$$$$$ \ $$ | $$$$$$ | $$$$$$ |
$$ |$$ \ _$$ |_ / \__$$ |/ \__$$ |
$$ | $$ |/ $$ |$$ $$/ $$ $$/
$$/ $$/ $$$$$$/ $$$$$$/ $$$$$$/
#>
param (
[Parameter(Mandatory = $true)]
[string]$VMName
)
################CHOP IT################
$Generation = 2
$HDDSize = 30GB
$ProcessorCount = 2
$StartupMEM = 4096MB
$VMPath = "C:\MMSLABS\QuickVM"
$VirtualSwitchName = "WAN"
$ISOPath = "C:\MMSLABS\ISO\W1121H2.iso"
$VHDXPath = (Join-Path -Path $VMPath -ChildPath $VMName) + ".vhdx"
################COOK IT################
#Create VM
If (Test-Path -Path (Join-Path -Path $VMPath -ChildPath $VMName)) {
Write-Warning "That VM Already exists, please specify a different VM name"
Exit 0
}
else {
New-VM -Name $VMName -Path $VMPath -MemoryStartupBytes $StartupMEM -SwitchName $VirtualSwitchName -Generation $Generation
}
#Change Processor Count
Set-VMProcessor -VMName $VMName -Count $ProcessorCount
#Create VHD
New-VHD -Path $VHDXPath -SizeBytes $HDDSize -Dynamic
Add-VMHardDiskDrive -VMName $VMName -Path $VHDXPath
#Attach ISO
Add-VMDvdDrive -VMName $VMName -Path $ISOPath
#Change Boot Order
$BootDVD = Get-VMFirmware $VMName | Select-Object -ExpandProperty BootOrder | where-object { $_.Device -like "DVD*" }
$BootHDD = Get-VMFirmware $VMName | Select-Object -ExpandProperty BootOrder | where-object { $_.Device -like "HardDiskDrive*" }
$BootPXE = Get-VMFirmware $VMName | Select-Object -ExpandProperty BootOrder | where-object { $_.Device -like "VMNetwork*" }
Set-VMFirmware -VMName $VMName -BootOrder $BootHDD, $BootDVD, $BootPXE
#Enable TPM
Set-VMKeyProtector -VMName $VMName -NewLocalKeyProtector
Enable-VMTPM -VMName $VMName
################CRANK IT################
#Start VM
#Start-VM -Name $VMName