-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAutomated_Hyper-V_VM_Deployment_Script
More file actions
79 lines (76 loc) · 2.79 KB
/
Copy pathAutomated_Hyper-V_VM_Deployment_Script
File metadata and controls
79 lines (76 loc) · 2.79 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Enter-PSSession -ComputerName 'hv.local' -Credential (Get-Credential -UserName "Administrator" -Message "Type password") -Verbose -ErrorAction Stop -Authentication Credssp
function create-vm {
param (
[string]$vm_name
)
$server_type = Read-Host "Put server service type"
$server_ip = Read-host "Put indicated IP Address"
$server_os = Read-Host "Specify Server OS - WIN or LIN"
$server_windows = "WIN"
$server_linux = "LIN"
#-----------------------------------------------------------------------------------
if ($server_os -eq $server_windows) {
$vm_name = "MAOX-$Server_windows-$server_type-$server_ip"
New-VHD -Path "C:\Virtual Machines\Windows\$($vm_name)\$($vm_name).vhdx" `
-Fixed `
-SizeBytes 40GB `
-ErrorAction Stop `
-Verbose `
-Confirm:$false
}
elseif ($server_os -eq $server_linux) {
$vm_name = "MAOX-$Server_linux-$server_type-$server_ip"
New-VHD -Path "C:\Virtual Machines\Linux\$($vm_name)\$($vm_name).vhdx" `
-Fixed `
-SizeBytes 40GB `
-ErrorAction Stop `
-Verbose `
-Confirm:$false
}
else {
Write-Host "It is mandotory to define OS WIN or LIN"
}
#-----------------------------------------------------------------------------------
if ($server_os -eq $server_windows) {
$vm_name = "MAOX-$Server_windows-$server_type-$server_ip"
New-VM -Name $vm_name `
-MemoryStartupBytes 2GB `
-VHDPath "C:\Virtual Machines\Windows\$($vm_name)\$($vm_name).vhdx" `
-SwitchName 'InternalSwitch1' `
-Path "C:\Virtual Machines\Windows\$($vm_name)" `
-Generation 1 `
-Confirm:$false `
-BootDevice CD `
-Verbose
}
elseif ($server_os -eq $server_linux) {
$vm_name = "MAOX-$Server_linux-$server_type-$server_ip"
New-VM -Name $vm_name `
-MemoryStartupBytes 2GB `
-VHDPath "C:\Virtual Machines\Linux\$($vm_name)\$($vm_name).vhdx" `
-SwitchName 'InternalSwitch1' `
-Path "C:\Virtual Machines\Linux\$($vm_name)" `
-Generation 1 `
-Confirm:$false `
-BootDevice CD `
-Verbose
}
else {
Write-Host-Host "It is mandotory to define OS WIN or LIN"
}
#-----------------------------------------------------------------------------------
Add-VMDvdDrive -VMName $vm_name -Path "C:\ISO\Windows Server 2022.iso" -Confirm:$false -Verbose
return Start-VM $vm_name
}
$yes = "yes"
$no = "no"
$vm_power = Read-Host "Type yes or no"
if ($vm_power -eq $yes) {
create-vm
}
elseif ($vm_power -eq $no) {
Write-Host "Cant create VMs"
}
else {
Write-Host "You put no condtions, MF ! :)"
}