192 lines
6.3 KiB
PowerShell
192 lines
6.3 KiB
PowerShell
## 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"
|
|
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-01.vhdx
|
|
|
|
$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 + ":"
|
|
Copy-Item D:\Scripts\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
|
|
Copy-Item D:\Scripts\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
|
|
mkdir "${Driveletter}:\Tools\Scripts"
|
|
Copy-item d:\Scripts\Guests\SRV-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
|
|
|
|
Dismount-VHD d:\VHD\SRV-01.vhdx
|
|
|
|
$vms = @{
|
|
|
|
Name = "SRV-01"
|
|
Generation = '2'
|
|
MemoryStartupBytes = 1024Mb
|
|
VHDPath = "d:\VHD\SRV-01.vhdx"
|
|
SwitchName = "Arc-SRV"
|
|
}
|
|
|
|
New-VM @vms
|
|
Set-VMMemory SRV-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
|
|
Set-VM -Name SRV-01 -ProcessorCount 2
|
|
|
|
echo "Configuring adapters"
|
|
Rename-VMNetworkAdapter -VMName 'SRV-01' -NewName 'Arc-SRV'
|
|
Set-VMNetworkAdapter -VMName 'SRV-01' -Name "Arc-SRV" -DeviceNaming on
|
|
|
|
### Adding SRV-03
|
|
|
|
echo "Adding and configuring SRV-03"
|
|
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-03.vhdx
|
|
|
|
$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 + ":"
|
|
Copy-Item D:\Scripts\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
|
|
Copy-Item D:\Scripts\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
|
|
mkdir "${Driveletter}:\Tools\Scripts"
|
|
Copy-item d:\Scripts\Guests\SRV-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
|
|
|
|
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"
|
|
|
|
Rename-VMNetworkAdapter -VMName 'SRV-03' -NewName 'Bou-LAN'
|
|
Set-VMNetworkAdapter -VMName 'SRV-03' -Name "Bou-Lan" -DeviceNaming on
|
|
|
|
|
|
### Adding and configuring RTR-01
|
|
|
|
echo "Adding and configuring RTR-01"
|
|
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-01.vhdx
|
|
|
|
$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 + ":"
|
|
Copy-Item D:\Scripts\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
|
|
Copy-Item D:\Scripts\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
|
|
mkdir "${Driveletter}:\Tools\Scripts"
|
|
Copy-item d:\Scripts\Guests\RTR-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
|
|
|
|
Dismount-VHD d:\VHD\RTR-01.vhdx
|
|
|
|
$vms = @{
|
|
|
|
Name = "RTR-01"
|
|
Generation = '2'
|
|
MemoryStartupBytes = 1024Mb
|
|
VHDPath = "d:\VHD\RTR-01.vhdx"
|
|
SwitchName = "Arc-SRV"
|
|
}
|
|
|
|
New-VM @vms
|
|
Set-VMMemory RTR-01 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
|
|
Set-VM -Name RTR-01 -ProcessorCount 2
|
|
|
|
echo "Configuring adapters"
|
|
#Set-VMNetworkAdapter -VMNetworkAdapter $vmadapter[0] -Name "Arc-SRV" -DeviceNaming on
|
|
Rename-VMNetworkAdapter -VMName 'RTR-01' -NewName 'Arc-SRV'
|
|
Set-VMNetworkAdapter -VMName 'RTR-01' -Name "Arc-SRV" -DeviceNaming on
|
|
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "Arc-CLI" -Name "Arc-Cli" -DeviceNaming on
|
|
Add-VMNetworkAdapter -VMName "RTR-01" -SwitchName "WAN" -Name "WAN" -DeviceNaming on
|
|
|
|
|
|
# RTR-02
|
|
|
|
echo "Adding and configuring RTR-02"
|
|
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-02.vhdx
|
|
|
|
$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 + ":"
|
|
Copy-Item D:\Scripts\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
|
|
Copy-Item D:\Scripts\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
|
|
mkdir "${Driveletter}:\Tools\Scripts"
|
|
Copy-item d:\Scripts\Guests\RTR-02.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
|
|
|
|
Dismount-VHD d:\VHD\RTR-02.vhdx
|
|
|
|
$vms = @{
|
|
|
|
Name = "RTR-02"
|
|
Generation = '2'
|
|
MemoryStartupBytes = 1024Mb
|
|
VHDPath = "d:\VHD\RTR-02.vhdx"
|
|
SwitchName = "Bou-LAN"
|
|
}
|
|
|
|
New-VM @vms
|
|
|
|
Set-VMMemory RTR-02 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
|
|
Set-VM -Name RTR-02 -ProcessorCount 2
|
|
|
|
echo "Configuring adapters"
|
|
Rename-VMNetworkAdapter -VMName 'RTR-02' -NewName 'Bou-Lan'
|
|
Set-VMNetworkAdapter -VMName 'RTR-02' -Name "Bou-LAN" -DeviceNaming on
|
|
Add-VMNetworkAdapter -VMName "RTR-02" -SwitchName "WAN" -Name "WAN" -DeviceNaming on
|
|
|
|
|
|
|
|
# RTR-03
|
|
|
|
echo "Adding and configuring RTR-03"
|
|
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-03.vhdx
|
|
|
|
$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 + ":"
|
|
Copy-Item D:\Scripts\Unattend\FullUnattend-srv.xml -Destination "$Drive\Windows\Panther\Unattend.xml"
|
|
Copy-Item D:\Scripts\deploy.cmd -Destination "${Driveletter}:\conf\deploy.cmd"
|
|
mkdir "${Driveletter}:\Tools\Scripts"
|
|
Copy-item d:\Scripts\Guests\RTR-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
|
|
|
|
Dismount-VHD d:\VHD\RTR-03.vhdx
|
|
|
|
$vms = @{
|
|
|
|
Name = "RTR-03"
|
|
Generation = '2'
|
|
MemoryStartupBytes = 1024Mb
|
|
VHDPath = "d:\VHD\RTR-03.vhdx"
|
|
SwitchName = "WAN"
|
|
}
|
|
|
|
New-VM @vms
|
|
|
|
Set-VMMemory RTR-03 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB
|
|
Set-VM -Name RTR-03 -ProcessorCount 2
|
|
|
|
echo "Configuring adapters"
|
|
Rename-VMNetworkAdapter -VMName 'RTR-03' -NewName 'WAN'
|
|
Set-VMNetworkAdapter -VMName 'RTR-03' -Name "WAN" -DeviceNaming on
|
|
Add-VMNetworkAdapter -VMName "RTR-03" -SwitchName "Aston" -Name "Aston" -DeviceNaming on
|
|
|
|
### Starting VMS
|
|
echo "Starting VMs"
|
|
Start-VM -Name RTR*
|
|
|
|
### Sleeping 15s
|
|
|
|
echo "Sleeping 15s"
|
|
|
|
Sleep 15
|
|
|
|
|
|
Start-VM -Name SRV*
|