diff --git a/Host/Bootstrap-Hyper-V.ps1 b/Host/Bootstrap-Hyper-V.ps1 index 8a8512f..5f37777 100644 --- a/Host/Bootstrap-Hyper-V.ps1 +++ b/Host/Bootstrap-Hyper-V.ps1 @@ -8,12 +8,13 @@ echo "GPLv3" $base_cli = Read-Host "CLI base disk name with extension?" $base_srv = Read-Host "SRV base disk name with extension?" $base_vhd_path = "${vhd_path}Base\" -$scripts_path = Read-host "Scripts path with trailling slash?" +$soft_path = Read-host "Software directory with trailing slash?" +$scripts_path = Read-host "Scripts path with trailing slash?" $source_cli_name = Read-Host "CLI source disk name with extension?" -$source_path = Read-host "Actual source path with trailling slash?" +$source_path = Read-host "Actual source path with trailing slash?" $source_srv_name = Read-Host "SRV source disk name with extension?" -$vhd_path = Read-host "VHD path with trailling slash?" -$vm_path = Read-Host "VM path with trailling slash?" +$vhd_path = Read-host "VHD path with trailing slash?" +$vm_path = Read-Host "VM path with trailing slash?" ### Store them as ENV vars diff --git a/Host/Create-ALL.ps1 b/Host/Create-ALL.ps1 index f27ef81..982e963 100644 --- a/Host/Create-ALL.ps1 +++ b/Host/Create-ALL.ps1 @@ -3,216 +3,74 @@ echo "Shamefully made by Alexandre Simao. Pardon-me dear M. Stallman" echo "GPLv3" -### Considered as finished. Need improvement VM side. - -$VM_list= import-csv ./VM_list.csv +$VM_list= import-csv ./VM_list.csv -delimiter "," $i = 0 $j = 1 -foreach ($VM_list.VM_name in $VM_list) { +$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 - echo "Adding and configuring ($VM_list.VM_Name[$i])"; - $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 "${Driveletter}:\Tools\Scripts"; - Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"; - +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"; + } + Dismount-VHD "$env:VHD_PATH$vm_name.vhdx"; - New-VM -Name "($VM_list.VM_name[$i])" -generation "($VM_list.gen[$i])" -memorystartupbytes "$(VM_list.mem[$i])"; - Set-VMHardDiskDrive -VMName "($VM_list.VM_name[$i])" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI; - Set-VMMemory "($VM_list.VM_name[$i])" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem; - Set-VM -Name "($VM_list.VM_name[$i])" -ProcessorCount "($VM_list_cpus[$i])" - + 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])" + echo "Configuring adapters"; - Rename-VMNetworkAdapter -VMName "($VM_list.VM_name[$i]) -NewName "($VM_list.switch_name[$i]); - Set-VMNetworkAdapter -VMName "($VM_list.VM_name[$i]) -Name "($VM_list.switch_name[$i]) -DeviceNaming on; - if ( ($VM_list.switch_name$j[$i]) -ne $null) { - Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name2" -Name "Arc-SRV" -DeviceNaming on - Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name3" -Name "WAN" -DeviceNaming on + 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++ + } -### Adding SRV-01 - -$vm_name = "SRV-01" -$switch_name = "Arc-SRV" -$gen = 2 -$mem = 1024MB -$min_mem = 512MB -$max_mem = 2048MB -$cpus = 2 - -echo "Adding and configuring $vm_name" -cp "$env:BASE_VHD_PATH$env:BASE_SRV_NAME" "$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 "${Driveletter}:\Tools\Scripts" -Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1" - -Dismount-VHD "$env:VHD_PATH$vm_name.vhdx" - -New-VM -Name "$vm_name" -generation "$gen" -memorystartupbytes $mem -Set-VMHardDiskDrive -VMName "$vm_name" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI -Set-VMMemory "$vm_name" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem -Set-VM -Name "$vm_name" -ProcessorCount "$cpus" - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on - -### Adding SRV-03 - -$vm_name = "SRV-01" -$switch_name = "Arc-SRV" -$gen = 2 -$mem = 1024MB -$min_mem = 512MB -$max_mem = 2048MB -$cpus = 2 - -echo "Adding and configuring $vm_name" -cp "$env:BASE_VHD_PATH$env:BASE_SRV_NAME" "$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 "${Driveletter}:\Tools\Scripts" -Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1" - -Dismount-VHD "$env:VHD_PATH$vm_name.vhdx" - -New-VM -Name "$vm_name" -generation "$gen" -memorystartupbytes $mem -Set-VMHardDiskDrive -VMName "$vm_name" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI -Set-VMMemory "$vm_name" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem -Set-VM -Name "$vm_name" -ProcessorCount "$cpus" - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on - -### Adding and configuring RTR-01 - -$vm_name = "RTR-01" -$switch_name = "Arc-CLI" -$switch_name2 = "Arc-SRV" -$switch_name3 = "WAN" -$gen = 2 -$mem = 1024MB -$min_mem = 512MB -$max_mem = 2048MB -$cpus = 2 - -echo "Adding and configuring $vm_name" -cp "$env:BASE_VHD_PATH$env:BASE_SRV_NAME" "$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 "${Driveletter}:\Tools\Scripts" -Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1" - -Dismount-VHD "$env:VHD_PATH$vm_name.vhdx" - -New-VM -Name "$vm_name" -generation "$gen" -memorystartupbytes $mem -Set-VMHardDiskDrive -VMName "$vm_name" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI -Set-VMMemory "$vm_name" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem -Set-VM -Name "$vm_name" -ProcessorCount "$cpus" - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on -Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name2" -Name "Arc-SRV" -DeviceNaming on -Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name3" -Name "WAN" -DeviceNaming on - -# RTR-02 - -$vm_name = "RTR-02" -$switch_name = "Bou-LAN" -$switch_name2 = "WAN" -$gen = 2 -$mem = 1024MB -$min_mem = 512MB -$max_mem = 2048MB -$cpus = 2 - -echo "Adding and configuring $vm_name" -cp "$env:BASE_VHD_PATH$env:BASE_SRV_NAME" "$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 "${Driveletter}:\Tools\Scripts" -Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1" - -Dismount-VHD "$env:VHD_PATH$vm_name.vhdx" - -New-VM -Name "$vm_name" -generation "$gen" -memorystartupbytes $mem -Set-VMHardDiskDrive -VMName "$vm_name" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI -Set-VMMemory "$vm_name" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem -Set-VM -Name "$vm_name" -ProcessorCount "$cpus" - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on -Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name2" -Name "$switch_name2" -DeviceNaming on - -# RTR-03 - -$vm_name = "RTR-03" -$switch_name = "Aston" -$switch_name3 = "WAN" -$gen = 2 -$mem = 1024MB -$min_mem = 512MB -$max_mem = 2048MB -$cpus = 2 - -echo "Adding and configuring $vm_name" -cp "$env:BASE_VHD_PATH$env:BASE_SRV_NAME" "$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 "${Driveletter}:\Tools\Scripts" -Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1" - -Dismount-VHD $env:VHD_PATH$vm_name.vhdx - -New-VM -Name "$vm_name" -generation "$gen" -memorystartupbytes $mem -Set-VMHardDiskDrive -VMName "$vm_name" -Path "$env:VHD_PATH$vm_name.vhdx" -ControllerType SCSI -Set-VMMemory "$vm_name" -DynamicMemoryEnabled $true -MinimumBytes $min_mem -StartupBytes $mem -MaximumBytes $max_mem -Set-VM -Name "$vm_name" -ProcessorCount "$cpus" - -echo "Configuring adapters" -Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name" -Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on -Add-VMNetworkAdapter -VMName "$vm_name" -SwitchName "$switch_name2" -Name "$switch_name2" -DeviceNaming on - ### Starting VMS echo "Starting VMs" diff --git a/Host/VM_list.csv b/Host/VM_list.csv index 8c22a13..9811be0 100644 --- a/Host/VM_list.csv +++ b/Host/VM_list.csv @@ -6,5 +6,5 @@ "RTR-02","Bou-LAN","WAN","","2","512","1024","2048","2" "RTR-03","WAN","Aston","","2","512","1024","2048","2" "CLI-01","Arc-CLI","","","1","512","512","1024","2" -"CLI-01","Arc-CLI","","","1","512","512","1024","2" +"CLI-02","Arc-CLI","","","1","512","512","1024","2" "CLI-03","Bou-LAN","","","1","512","512","1024","2"