2021-04-20 11:39:24 +02:00
|
|
|
## Tool to automate VM creation
|
|
|
|
|
2021-04-23 12:54:01 +02:00
|
|
|
echo "Shamefully made by Alexandre Simao. Pardon-me dear M. Stallman"
|
|
|
|
echo "GPLv3"
|
2021-04-21 12:16:54 +02:00
|
|
|
|
2021-06-30 16:40:57 +02:00
|
|
|
$VM_list= import-csv ./VM_list.csv -delimiter ","
|
2021-06-30 13:16:51 +02:00
|
|
|
$i = 0
|
|
|
|
$j = 1
|
|
|
|
|
2021-06-30 16:40:57 +02:00
|
|
|
$VM_Name = $VM_list.VM_name
|
|
|
|
$Switch_name = $VM_list.Switch_name
|
|
|
|
$Switch_name2 = $VM_list.Switch_name2
|
|
|
|
$Switch_Name3 = $VM_list.Switch_name3
|
|
|
|
$Gen = $VM_list.Gen
|
|
|
|
$Min_mem = $VM_list.Min_mem
|
|
|
|
$Mem = $VM_list.Min_mem
|
|
|
|
$Max_mem = $VM_list.Max_mem
|
|
|
|
$CPUs = $VM_list.Max_mem
|
|
|
|
|
|
|
|
foreach ($VM in $VM_list) {
|
|
|
|
|
|
|
|
echo "Adding and configuring ($VM_List.VM_Name[$i])";
|
|
|
|
|
|
|
|
if ( ($VM.VM_name[$i]) -Like "SRV*") {
|
|
|
|
|
|
|
|
Copy-Item "${env:BASE_VHD_PATH}${env:BASE_SRV}" "${env:VHD_PATH}${VM_NAME}.vhdx"
|
|
|
|
$Lettre = Mount-VHD -Path $env:VHD_PATH$vm_name.VHDx -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1;
|
|
|
|
$DriveLetter = $Lettre.DriveLetter;
|
|
|
|
$drive = $DriveLetter + ":";
|
|
|
|
New-Item -Path "${Driveletter}:\conf\" -Name "Base" -ItemType "directory";
|
|
|
|
Copy-Item "${env:SCRIPTS_PATH}Unattend\FullUnattend-srv.xml" -Destination "$Drive\Windows\Panther\Unattend.xml";
|
|
|
|
Copy-Item "${env:SCRIPTS_PATH}deploy.cmd" -Destination "${Drive}\conf\deploy.cmd";
|
|
|
|
mkdir "${Drive}\Tools\Scripts";
|
|
|
|
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1";
|
|
|
|
|
|
|
|
Dismount-VHD "$env:VHD_PATH($VM.VM_name[$i]).vhdx";
|
|
|
|
|
|
|
|
New-VM -Name "($VM.VM_name[$i])" -generation "($VM.gen[$i])" -memorystartupbytes "$(VM_list.mem[$i])";
|
|
|
|
Set-VMHardDiskDrive -VMName "($VM.VM_name[$i])" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI;
|
|
|
|
Set-VMMemory "($VM.VM_name[$i])" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem;
|
|
|
|
Set-VM -Name "($VM.VM_name[$i])" -ProcessorCount "($VM_cpus[$i])"
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ($VM.VM_name[$i]) -Like "CLI*") {
|
|
|
|
$Lettre = Mount-VHD -Path $env:VHD_PATH$vm_name.VHDx -PassThru | Get-Disk | Get-Partition | Get-Volume | Sort-Object -Property Size -Descending | Select-Object -First 1;
|
|
|
|
$DriveLetter = $Lettre.DriveLetter;
|
|
|
|
$drive = $DriveLetter + ":";
|
|
|
|
Copy-Item "${env:SCRIPTS_PATH}Unattend\FullUnattend-Win10.xml" -Destination "$Drive\Windows\Panther\Unattend.xml";
|
|
|
|
Copy-Item "${env:SCRIPTS_PATH}deploy.cmd" -Destination "${Drive}\conf\deploy.cmd";
|
|
|
|
mkdir "${drive}:\Program Files\BGINFO";
|
|
|
|
Copy-Item "${env:soft_path}"BGInfo_Deploiement\BGInfo.exe "${drive}\Program Files\BGINFO";
|
|
|
|
Copy-Item "${env:soft_path}"BGInfo_Deploiement\mescouilles2.bgi "${drive}\Program Files\BGINFO";
|
|
|
|
Copy-Item "${env:soft_path}"BGInfo_Deploiement\bginfox86.bat "${drive}\Users\AdminLocal\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup";
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:16:51 +02:00
|
|
|
Dismount-VHD "$env:VHD_PATH$vm_name.vhdx";
|
|
|
|
|
2021-06-30 16:40:57 +02:00
|
|
|
New-VM -Name "($VM.VM_name[$i])" -generation "($VM.gen[$i])" -memorystartupbytes "$(VM_list.mem[$i])";
|
|
|
|
Set-VMHardDiskDrive -VMName "($VM.VM_name[$i])" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI;
|
|
|
|
Set-VMMemory "($VM.VM_name[$i])" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem;
|
|
|
|
Set-VM -Name "($VM.VM_name[$i])" -ProcessorCount "($VM_cpus[$i])"
|
|
|
|
|
2021-06-30 13:16:51 +02:00
|
|
|
echo "Configuring adapters";
|
2021-06-30 16:40:57 +02:00
|
|
|
Rename-VMNetworkAdapter -VMName "($VM.VM_name[$i])" -NewName "($VM.switch_name[$i])";
|
|
|
|
Set-VMNetworkAdapter -VMName "($VM.VM_name[$i])" -Name "($VM.switch_name[$i])" -DeviceNaming on;
|
|
|
|
while ( ("$VM.switch_name$j"[$i]) -ne $null) {
|
|
|
|
Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name$j" -Name "$switch_name$j" -DeviceNaming on;
|
|
|
|
$j++
|
|
|
|
}
|
|
|
|
$i++
|
|
|
|
|
2021-06-30 13:16:51 +02:00
|
|
|
}
|
|
|
|
|
2021-04-23 12:54:01 +02:00
|
|
|
### Starting VMS
|
2021-06-29 15:56:38 +02:00
|
|
|
|
2021-04-23 12:54:01 +02:00
|
|
|
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-05-10 17:28:09 +02:00
|
|
|
|
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*
|