Aston-HyperV-Code/Host/Serveurs.ps1

188 lines
5.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. Pardon-me dear M. Stallman"
echo "GPLv3"
### Considered as finished. Need improvement VM side.
### Adding SRV-01
echo "Adding and configuring SRV-01"
2021-05-10 11:35:41 +02:00
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-01.vhdx
Mount-VHD d:\VHD\SRV-01.vhdx
2021-05-12 16:25:20 +02:00
Copy-Item d:\Unattend\server.xml -Destination e:\Windows\Panther\Unattend.xml
mkdir e:\Tools\Scripts
2021-05-12 16:52:54 +02:00
mkdir "e:\Program Files\BGINFO"
2021-05-12 16:25:20 +02:00
Copy-item d:\Scripts\Guests\SRV-01.ps1 E:\Tools\scripts\boot.ps1
2021-05-12 16:52:54 +02:00
Copy-Item D:\Soft\BGInfo_Deploiement\BGInfo64.exe "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\mescouilles2.bgi "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\bginfo.bat "e:\Program Files\BGINFO\"
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
2021-04-22 15:58:53 +02:00
VHDPath = "d:\VHD\SRV-01.vhdx"
2021-04-22 17:26:29 +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 SRV-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
2021-04-22 15:58:53 +02:00
Set-VM -Name SRV-01 -ProcessorCount 2
echo "Configuring adapters"
2021-04-22 17:26:29 +02:00
Rename-VMNetworkAdapter -VMName 'SRV-01' -NewName 'Arc-SRV'
Set-VMNetworkAdapter -VMName 'SRV-01' -Name "Arc-SRV" -DeviceNaming on
2021-04-22 15:58:53 +02:00
2021-05-14 10:29:48 +02:00
### Adding SRV-03
echo "Adding and configuring SRV-03"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-03.vhdx
Mount-VHD d:\VHD\SRV-03.vhdx
Copy-Item d:\Unattend\server.xml -Destination e:\Windows\Panther\Unattend.xml
mkdir e:\Tools\Scripts
mkdir "e:\Program Files\BGINFO"
Copy-item d:\Scripts\Guests\SRV-03.ps1 E:\Tools\scripts\boot.ps1
Copy-Item D:\Soft\BGInfo_Deploiement\BGInfo64.exe "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\mescouilles2.bgi "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\bginfo.bat "e:\Program Files\BGINFO\"
Dismount-VHD d:\VHD\SRV-01.vhdx
2021-05-14 10:29:48 +02:00
$vms = @{
Name = "SRV-03"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\SRV-03.vhdx"
SwitchName = "Bou-LAN"
2021-05-14 10:29:48 +02:00
New-VM @vms
Set-VMMemory SRV-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Set-VM -Name SRV-03 -ProcessorCount 2
echo "Configuring adapters"
Rename-VMNetworkAdapter -VMName 'SRV-03' -NewName 'Arc-SRV'
Set-VMNetworkAdapter -VMName 'SRV-03' -Name "Arc-SRV" -DeviceNaming on
2021-04-20 11:39:24 +02:00
### Adding and configuring RTR-01
2021-04-20 15:25:09 +02:00
echo "Adding and configuring RTR-01"
2021-05-10 11:35:41 +02:00
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-01.vhdx
Mount-VHD d:\VHD\RTR-01.vhdx
2021-05-12 16:25:20 +02:00
Copy-Item d:\Unattend\server.xml -Destination e:\Windows\Panther\Unattend.xml
mkdir e:\Tools\Scripts
2021-05-12 16:52:54 +02:00
mkdir "e:\Program Files\BGINFO"
2021-05-12 16:25:20 +02:00
Copy-item d:\Scripts\Guests\RTR-01.ps1 E:\Tools\scripts\boot.ps1
2021-05-12 16:52:54 +02:00
Copy-Item D:\Soft\BGInfo_Deploiement\BGInfo64.exe "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\mescouilles2.bgi "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\bginfo.bat "e:\Program Files\BGINFO\"
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-22 17:26:29 +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
2021-04-22 15:58:53 +02:00
Set-VM -Name RTR-01 -ProcessorCount 2
echo "Configuring adapters"
2021-04-21 17:59:14 +02:00
#Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -Name "Arc-SRV" -DeviceNaming on
2021-04-22 17:26:29 +02:00
Rename-VMNetworkAdapter -VMName 'RTR-01' -NewName 'Arc-SRV'
Set-VMNetworkAdapter -VMName 'RTR-01' -Name "Arc-SRV" -DeviceNaming on
2021-04-21 17:59:14 +02:00
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -Name "Arc-Cli" -DeviceNaming on
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" -Name "WAN" -DeviceNaming on
2021-04-22 17:26:29 +02:00
2021-04-20 15:25:09 +02:00
# RTR-02
2021-04-20 11:39:24 +02:00
echo "Adding and configuring RTR-02"
2021-05-10 11:35:41 +02:00
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-02.vhdx
Mount-VHD d:\VHD\RTR-02.vhdx
2021-05-12 16:25:20 +02:00
Copy-Item d:\Unattend\server.xml -Destination e:\Windows\Panther\Unattend.xml
mkdir e:\Tools\Scripts
2021-05-12 16:52:54 +02:00
mkdir "e:\Program Files\BGINFO"
2021-05-12 16:25:20 +02:00
Copy-item D:\scripts\Guests\RTR-02.ps1 E:\Tools\scripts\boot.ps1
2021-05-12 16:52:54 +02:00
Copy-Item D:\Soft\BGInfo_Deploiement\BGInfo64.exe "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\mescouilles2.bgi "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\bginfo.bat "e:\Program Files\BGINFO\"
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
2021-04-22 15:58:53 +02:00
VHDPath = "d:\VHD\RTR-02.vhdx"
2021-04-22 17:26:29 +02:00
SwitchName = "Bou-LAN"
}
2021-04-20 11:39:24 +02:00
New-VM @vms
2021-04-21 15:00:09 +02:00
2021-04-22 15:58:53 +02:00
Set-VMMemory RTR-02 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
Set-VM -Name RTR-02 -ProcessorCount 2
2021-04-21 15:00:09 +02:00
echo "Configuring adapters"
2021-04-22 17:26:29 +02:00
Rename-VMNetworkAdapter -VMName 'RTR-02' -NewName 'Bou-Lan'
Set-VMNetworkAdapter -VMName 'RTR-02' -Name "Bou-LAN" -DeviceNaming on
2021-04-22 10:46:50 +02:00
Add-VMNetworkAdapter -VMName "RTR-02" -SwitchName "WAN" -Name "WAN" -DeviceNaming on
2021-04-21 15:00:09 +02:00
2021-04-20 15:25:09 +02:00
2021-04-22 17:26:29 +02:00
2021-04-20 15:25:09 +02:00
# RTR-03
2021-04-20 11:39:24 +02:00
echo "Adding and configuring RTR-03"
2021-05-10 11:35:41 +02:00
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-03.vhdx
Mount-VHD d:\VHD\RTR-03.vhdx
2021-05-12 16:25:20 +02:00
Copy-Item d:\Unattend\server.xml -Destination e:\Windows\Panther\Unattend.xml
mkdir e:\Tools\Scripts
2021-05-12 16:52:54 +02:00
mkdir "e:\Program Files\BGINFO"
2021-05-12 16:25:20 +02:00
Copy-item d:\Scripts\Guests\RTR-03.ps1 E:\Tools\scripts\boot.ps1
2021-05-12 16:52:54 +02:00
Copy-Item D:\Soft\BGInfo_Deploiement\BGInfo64.exe "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\mescouilles2.bgi "e:\Program Files\BGINFO\"
Copy-Item D:\Soft\BGInfo_Deploiement\bginfo.bat "e:\Program Files\BGINFO\"
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
2021-04-22 15:58:53 +02:00
VHDPath = "d:\VHD\RTR-03.vhdx"
2021-04-22 17:26:29 +02:00
SwitchName = "WAN"
}
2021-04-20 17:28:39 +02:00
New-VM @vms
2021-04-21 15:00:09 +02:00
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
2021-04-22 15:58:53 +02:00
Set-VM -Name RTR-03 -ProcessorCount 2
2021-04-21 15:00:09 +02:00
echo "Configuring adapters"
2021-04-22 17:26:29 +02:00
Rename-VMNetworkAdapter -VMName 'RTR-03' -NewName 'WAN'
Set-VMNetworkAdapter -VMName 'RTR-03' -Name "WAN" -DeviceNaming on
2021-04-22 10:46:50 +02:00
Add-VMNetworkAdapter -VMName "RTR-03" -SwitchName "Aston" -Name "Aston" -DeviceNaming on
2021-04-22 17:26:29 +02:00
### Starting VMS
echo "Starting VMs"
2021-04-20 15:25:09 +02:00
Start-VM -Name RTR*
2021-05-10 17:23:11 +02:00
2021-05-12 10:48:52 +02:00
### Sleeping 30s
2021-05-12 10:48:52 +02:00
echo "Sleeping 30"
Sleep 30
2021-05-10 17:23:11 +02:00
2021-04-20 15:25:09 +02:00
Start-VM -Name SRV*