Aston-HyperV-Code/Host/Create-ALL.ps1

201 lines
6.7 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.
2021-06-28 16:49:27 +02:00
### Define vars
$scripts_path = d:\scripts
### 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
2021-06-01 12:48:25 +02:00
$Lettre = Mount-VHD -Path "d:\VHD\SRV-01.VHDx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1
$DriveLetter = $Lettre.DriveLetter
$drive = $DriveLetter + ":"
2021-06-28 16:11:41 +02:00
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory"
2021-06-28 16:49:27 +02:00
Copy-Item ${scripts_path}\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
Copy-Item ${scripts_path}\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
2021-06-01 12:48:25 +02:00
mkdir "${Driveletter}:\Tools\Scripts"
2021-06-28 16:49:27 +02:00
Copy-item ${scripts_path}\Guests\SRV-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
2021-06-01 11:40:58 +02:00
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-31 14:34:24 +02:00
### Adding SRV-03
echo "Adding and configuring SRV-03"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-03.vhdx
2021-06-01 12:48:25 +02:00
$Lettre = Mount-VHD -Path "d:\VHD\SRV-03.VHDx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1
$DriveLetter = $Lettre.DriveLetter
$drive = $DriveLetter + ":"
2021-06-28 16:11:41 +02:00
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory"
2021-06-28 16:49:27 +02:00
Copy-Item ${scripts_path}\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
Copy-Item ${scripts_path}\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
2021-06-01 12:48:25 +02:00
mkdir "${Driveletter}:\Tools\Scripts"
2021-06-28 16:49:27 +02:00
Copy-item ${scripts_path}\Guests\SRV-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
2021-06-01 12:48:25 +02:00
2021-05-31 14:34:24 +02:00
Dismount-VHD d:\VHD\SRV-03.vhdx
$vms = @{
Name = "SRV-03"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\SRV-03.vhdx"
SwitchName = "Bou-LAN"
}
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"
2021-06-01 11:40:58 +02:00
2021-05-31 14:34:24 +02:00
Rename-VMNetworkAdapter -VMName 'SRV-03' -NewName 'Bou-LAN'
Set-VMNetworkAdapter -VMName 'SRV-03' -Name "Bou-Lan" -DeviceNaming on
2021-06-01 11:40:58 +02:00
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
2021-06-01 12:48:25 +02:00
$Lettre = Mount-VHD -Path "d:\VHD\RTR-01.VHDx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1
$DriveLetter = $Lettre.DriveLetter
$drive = $DriveLetter + ":"
2021-06-28 16:11:41 +02:00
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory"
2021-06-28 16:49:27 +02:00
Copy-Item ${scripts_path}\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
Copy-Item ${scripts_path}\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
2021-06-01 12:48:25 +02:00
mkdir "${Driveletter}:\Tools\Scripts"
2021-06-28 16:49:27 +02:00
Copy-item ${scripts_path}\Guests\RTR-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
2021-06-01 11:40:58 +02:00
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
2021-06-01 12:48:25 +02:00
$Lettre = Mount-VHD -Path "d:\VHD\RTR-02.VHDx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1
$DriveLetter = $Lettre.DriveLetter
$drive = $DriveLetter + ":"
2021-06-28 16:11:41 +02:00
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory"
2021-06-28 16:49:27 +02:00
Copy-Item ${scripts_path}\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
Copy-Item ${scripts_path}\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
2021-06-01 12:48:25 +02:00
mkdir "${Driveletter}:\Tools\Scripts"
2021-06-28 16:49:27 +02:00
Copy-item ${scripts_path}\Guests\RTR-02.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
2021-06-01 11:40:58 +02:00
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
2021-06-01 12:48:25 +02:00
$Lettre = Mount-VHD -Path "d:\VHD\RTR-03.VHDx" -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1
$DriveLetter = $Lettre.DriveLetter
$drive = $DriveLetter + ":"
2021-06-28 16:11:41 +02:00
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory"
2021-06-28 16:49:27 +02:00
Copy-Item ${scripts_path}\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
Copy-Item ${scripts_path}\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
2021-06-01 12:48:25 +02:00
mkdir "${Driveletter}:\Tools\Scripts"
2021-06-28 16:49:27 +02:00
Copy-item ${scripts_path}\Guests\RTR-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
2021-06-01 11:40:58 +02:00
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-06-01 12:48:25 +02:00
### Sleeping 15s
2021-06-01 12:48:25 +02:00
echo "Sleeping 15s"
2021-06-01 11:40:58 +02:00
2021-06-01 12:48:25 +02:00
Sleep 15
2021-06-01 11:40:58 +02:00
2021-05-10 17:23:11 +02:00
2021-04-20 15:25:09 +02:00
Start-VM -Name SRV*