-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-VM02.ps1
81 lines (48 loc) · 2.52 KB
/
New-VM02.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#Generic Konfiguration
$vSwitch = "LAN"
$VHDXCurrentPath = "G:\Hyper-V-VMs\sysprep\sysprep\Virtual Hard Disks"
$VHDXDestinationPath = "G:\Hyper-V-VMs\VMauto"
$SubMaskBit = "24"
#####################################
############Skapa Server01##############
$ADName = "Server01"
#Kopiera VM template som vi har skapat.
Write-Verbose "Check if folder for VM exist"
$cpath = Test-Path "G:\Hyper-V-VMs\VMauto\$($ADName)"
if($cpath -eq $false){
Write-Verbose "Folder doest not exist, creating folder" -Verbose
New-item -Name $ADName -Path "G:\Hyper-V-VMs\VMauto\" -ItemType Directory | Out-Null
Write-Verbose "Folder is created, copy template VM" -Verbose
Copy-Item "$VHDXCurrentPath\MASTER.vhdx" "$VHDXDestinationPath\$ADNAME\$ADNAME.vhdx"
}else{
Write-Verbose "Folder already exist" -Verbose
Write-Verbose "copy template VM" -Verbose
Copy-Item "$VHDXCurrentPath\MASTER.vhdx" "$VHDXDestinationPath\$DCNAME\$ADNAME.vhdx"
}
#Skapa VM Server01
New-VM -Name $ADName -MemoryStartupBytes 3GB -VHDPath "$VHDXDestinationPath\$ADNAME\$ADNAME.vhdx" -Generation 2 -SwitchName $vSwitch
Set-VM -Name $ADName -AutomaticCheckpointsEnabled $false
Write-Verbose "VM Creation Completed. Starting VM [$ADName]" -Verbose
Start-VM -Name $ADName
######################################################
######################################################
###################Skapa RDS server###################
$FileServer = "RDS01"
#Kopiera VM template till lagringplats
Write-Verbose "Check if folder for VM exist"
$cpath = Test-Path "G:\Hyper-V-VMs\VMauto\$($FileServer)"
if($cpath -eq $false){
Write-Verbose "Folder doest not exist, creating folder" -Verbose
New-item -Name $FileServer -Path "G:\Hyper-V-VMs\VMauto\" -ItemType Directory | Out-Null
Write-Verbose "Folder is created, copy template VM" -Verbose
Copy-Item "$VHDXCurrentPath\MASTER.vhdx" "$VHDXDestinationPath\$FileServer\$FileServer.vhdx"
}else{
Write-Verbose "Folder already exist" -Verbose
Write-Verbose "copy template VM" -Verbose
Copy-Item "$VHDXCurrentPath\MASTER.vhdx" "$VHDXDestinationPath\$FileServer\$FileServer.vhdx"
}
#Skapa VM File01
New-VM -Name $FileServer -MemoryStartupBytes 3GB -VHDPath "$VHDXDestinationPath\$FileServer\$FileServer.vhdx" -Generation 2 -SwitchName $vSwitch
Set-VM -Name $FileServer -AutomaticCheckpointsEnabled $false
Write-Verbose "VM Creation Completed. Starting VM [$FileServer]" -Verbose
Start-VM -Name $FileServer