-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabGenerator.ps1
37 lines (31 loc) · 1.37 KB
/
LabGenerator.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
Import-module Hyper-V
$LABVMs =@("Client01";"Client02";"Client03";"Client04")
$VMTemplate = "D:\Virtualization\TEMPLATE\Windows10.vhdx"
$LabPath = "D:\Virtualization\LAB"
$Switch = "Internal"
$Memsize = 1024MB
Foreach ($LABVM in $LABVMs) {
$VHD = Get-VHD -Path "$LabPath\$LABVM\$LABVM.vhdx" -ErrorAction SilentlyContinue
Write-Host "Creating VHD for VM $LABVM..." -NoNewline
If ($VHD -eq $null) {
New-VHD -ParentPath $VMTemplate -Path "$LabPath\$LABVM\$LABVM.vhdx" -Differencing | Out-Null
Write-Host -ForegroundColor Green " - VHD creation for $LABVM Done."
} else {
Write-Host -ForegroundColor Gray " - Already Created"
}
$VM = Get-VM -Name $LABVM -ErrorAction SilentlyContinue
Write-Host "Creating VM $LABVM..." -NoNewline
If ($VM.Name -ne $LABVM) {
New-VM -VHDPath "$LabPath\$LABVM\$LABVM.vhdx" -VMName $LABVM -MemoryStartupBytes $Memsize -SwitchName $Switch | Out-Null
Write-Host -ForegroundColor Green " - CONFIGURATION for $LABVM Done."
} else {
Write-Host -ForegroundColor Gray " - Already Created"
}
Write-Host "Starting VM $LABVM..." -NoNewline
If ($VM.State -ne "Running") {
Start-VM -Name $LABVM
Write-Host -ForegroundColor Green " - Done."
} else {
Write-Host -ForegroundColor Gray " - Already Running"
}
}