Aston-HyperV-Code/Host/Infra-Standard.ps1

106 lines
2.9 KiB
PowerShell
Raw Normal View History

2021-04-20 11:39:24 +02:00
## Tool to automate VM creation
echo "Shamefully made by Alexandre Simao. Such a waste of time.`
Pardon-me dear M. Stallman"
echo "CC BY-NC-SA 4.0"
2021-04-20 17:28:39 +02:00
# TODO: Export Mac/Name to import it on VMS
2021-04-20 11:39:24 +02:00
# Region SRV-01
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\SRV-01.vhdx
Mount-VHD d:\VHD\SRV-01.vhdx
Copy-Item d:\Unattend\SRV-01.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\SRV-01.vhdx
2021-04-20 11:39:24 +02:00
$vms = @{
Name = "SRV-01"
2021-04-20 11:39:24 +02:00
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
SwitchName = 'Arc-SRV'
2021-04-20 11:39:24 +02:00
}
2021-04-20 11:39:24 +02:00
New-VM @vms
Set-VMMemory SRV-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
$vmadapter = Get-VMNetworkAdapter -VMName "SRV-01"
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027000
# Endregion SRV-01
2021-04-20 11:39:24 +02:00
2021-04-20 15:25:09 +02:00
# RTR-01
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-01.vhdx
Mount-VHD d:\VHD\RTR-01.vhdx
Copy-Item d:\Unattend\RTR-01.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-01.vhdx
2021-04-20 11:39:24 +02:00
$vms = @{
Name = "RTR-01"
2021-04-20 11:39:24 +02:00
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\RTR-01.vhdx"
2021-04-20 15:25:09 +02:00
SwitchName = 'Arc-SRV'
2021-04-20 11:39:24 +02:00
}
2021-04-20 11:39:24 +02:00
New-VM @vms
Set-VMMemory RTR-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
$vmadapter = Get-VMNetworkAdapter -VMName "RTR-01"
Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -StaticMacAddress 00155D027001
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -StaticMacAddress 00155D027002
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" -StaticMacAddress 00155D027003
2021-04-20 15:25:09 +02:00
# RTR-02
2021-04-20 11:39:24 +02:00
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-02.vhdx
Mount-VHD d:\VHD\RTR-02.vhdx
Copy-Item d:\Unattend\RTR-02.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-02.vhdx
2021-04-20 11:39:24 +02:00
$vms = @{
Name = "RTR-02"
2021-04-20 11:39:24 +02:00
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
SwitchName = 'Arc-SRV'
}
2021-04-20 11:39:24 +02:00
New-VM @vms
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
2021-04-20 15:25:09 +02:00
#Add-VMSwitch -Name "WAN" -ResourcePoolName "WAN"
Add-VMNetworkAdapter -VMName RTR-02 -SwitchName "WAN" -StaticMacAddress 00155D027004
Add-VMNetworkAdapter -VMName RTR-02 -SwitchName "Bou-LAN" -StaticMacAddress 00155D027005
2021-04-20 15:25:09 +02:00
# RTR-03
2021-04-20 11:39:24 +02:00
cp D:\VHD\Base_dif\Base_server_g2.vhdx D:\VHD\RTR-03.vhdx
Mount-VHD d:\VHD\RTR-03.vhdx
Copy-Item d:\Unattend\RTR-03.xml -Destination e:\Windows\Panther\Unattend.xml
Dismount-VHD d:\VHD\RTR-03.vhdx
2021-04-20 11:39:24 +02:00
$vms = @{
Name = "RTR-03"
2021-04-20 11:39:24 +02:00
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\$VMName.vhdx"
2021-04-20 17:28:39 +02:00
}
2021-04-20 17:28:39 +02:00
New-VM @vms
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Add-VMNetworkAdapter -VMName RTR-03 -SwitchName "Aston" -StaticMacAddress 00155D027006
Add-VMNetworkAdapter -VMName RTR-03 -SwitchName "WAN" -StaticMacAddress 00155D027007
2021-04-20 17:28:39 +02:00
2021-04-20 15:25:09 +02:00
Start-VM -Name RTR*
Start-VM -Name SRV*