Compare commits

...

No commits in common. "master" and "refacto_foreach" have entirely different histories.

6 changed files with 133 additions and 194 deletions

View File

@ -1,6 +1,48 @@
New-Item -Path "d:\" -Name "VHD" -ItemType "directory"
New-Item -Path "d:\" -Name "VM" -ItemType "directory"
New-Item -Path "d:\VHD" -Name "Base" -ItemType "directory"
Move-Item d:/sources d:/VHD/
New-VHD -ParentPath d:\VHD\source\Base_2016_14393.161220_StdGUI_G2_upd28022017.vhdx -Path d:\VHD\Base\Base_SRV_diff.vhdx -Differencing
New-VHD -ParentPath d:\VHD\source\Master_Win10_20h2_x86_G1.vhdx -Path d:\VHD\Base\Base_CLI_diff.vhdx -Differencing
# Bootstrap script to init Hyper-v
echo "Shamefully made by Alexandre Simao. Pardon-me dear M. Stallman"
echo "GPLv3"
### Define variables
$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\"
$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 trailing slash?"
$source_srv_name = Read-Host "SRV source disk name with extension?"
$vhd_path = Read-host "VHD path with trailing slash?"
$vm_path = Read-Host "VM path with trailing slash?"
### Store them as ENV vars
$env:BASE_CLI_NAME = ${base_cli}
$env:BASE_SRV_NAME = ${base_srv}
$env:BASE_VHD_PATH = ${base_vhd_path}
$env:FULL_PATH = ${full_path}
$env:SCRIPTS_PATH = ${scripts_path}
$env:SOURCE_CLI_NAME = ${source_cli_name}
$env:SOURCE_PATH = ${source_path}
$env:SOURCE_SRV_NAME = ${source_srv_name}
$env:VM_PATH = ${vm_path}
$env:VHD_PATH = ${vhd_path}
### Let the fuckery begins!
md ${vhd_path}
md ${vhdpath}\Base
md ${vm_path}
Move-Item ${source_path} ${vhd_path}
New-VHD -ParentPath ${vhd_path}\source\${base_srv_name}.vhdx -Path ${vhd_path}\Base\${base_srv_name}.vhdx -Differencing
New-VHD -ParentPath ${vhd_path}\source\${source_cli_name}.vhdx -Path ${vhd_path}\${base_cli_name}.vhdx -Differencing
### Create VMNetworks
New-VMSwitch -name Arc-CLI -SwitchType Private
New-VMSwitch -name Arc-SRV -SwitchType Private
New-VMSwitch -name Bou-LAN -SwitchType Private
New-VMSwitch -name WAN -SwitchType Private
New-VMSwitch -name Aston -NetAdapterName Ethernet -AllowManagementOS $true

View File

@ -3,186 +3,76 @@
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 -delimiter ","
$i = 0
$j = 1
### Define vars
$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
$scripts_path = d:\scripts
foreach ($VM in $VM_list) {
### Adding SRV-01
echo "Adding and configuring ($VM_List.VM_Name[$i])";
echo "Adding and configuring SRV-01"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-01.vhdx
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])"
}
$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 ${scripts_path}\Guests\SRV-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
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.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])"
Dismount-VHD d:\VHD\SRV-01.vhdx
$vms = @{
Name = "SRV-01"
Generation = '2'
MemoryStartupBytes = 1024Mb
VHDPath = "d:\VHD\SRV-01.vhdx"
SwitchName = "Arc-SRV"
echo "Configuring adapters";
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++
}
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 ${scripts_path}\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 ${scripts_path}\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"
>>>>>>> parent of ca6ee46 (Feat: Add VNetwork creation)
mkdir "${Driveletter}:\Tools\Scripts"
Copy-item ${scripts_path}\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 ${scripts_path}\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*

10
Host/VM_list.csv Normal file
View File

@ -0,0 +1,10 @@
"VM_name","swith_name","switch_name2","switch_name3","gen","min_mem","mem","max_mem","cpus"
"SRV-01","Arc-SRV","","","2","512","1024","2048","2"
"SRV-02","Arc-SRV","","","2","512","1024","2048","2"
"SRV-03","Bou-LAN","","","2","512","1024","2048","2"
"RTR-01","Arc-CLI","Arc-SRV","WAN","2","512","1024","2048","2"
"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-02","Arc-CLI","","","1","512","512","1024","2"
"CLI-03","Bou-LAN","","","1","512","512","1024","2"
1 VM_name swith_name switch_name2 switch_name3 gen min_mem mem max_mem cpus
2 SRV-01 Arc-SRV 2 512 1024 2048 2
3 SRV-02 Arc-SRV 2 512 1024 2048 2
4 SRV-03 Bou-LAN 2 512 1024 2048 2
5 RTR-01 Arc-CLI Arc-SRV WAN 2 512 1024 2048 2
6 RTR-02 Bou-LAN WAN 2 512 1024 2048 2
7 RTR-03 WAN Aston 2 512 1024 2048 2
8 CLI-01 Arc-CLI 1 512 512 1024 2
9 CLI-02 Arc-CLI 1 512 512 1024 2
10 CLI-03 Bou-LAN 1 512 512 1024 2

View File

@ -1,12 +1,14 @@
# Aston Hyper-V code snipets
## Introduction
title: Aston Hyper-V Code Snippets
# Introduction
As a student at Aston Informatic School we mainly, and until now, exclusively studies Microsoft products.
Because I like to tinker, you'll find here some tools to put an infra in place.
For the moment, no Ansible, no Chef-Infra, no Terraform; no nice feature at all. I hope to resolve that later.
To achieve this ambitious goal, i'll use mainly PowerShell scripts.
As i feel that i'm in a strange marketing course for the evil mega-corporation, i'll try to pass the time quicker and focus on some side projects like the FreeIPA integration on a cursed Windows network.
To do that, i need to make the infra-building as quick as possible.
No Ansible, no Chef-Infra, no Terraform; no nice feature as all.
To achieve this ambitious goal, i'll use the ill-named PowerShell scripts.
## Usage
# Usage
First of all, here be dragons.
@ -17,15 +19,13 @@ The host folder contain all scripts needed for deploying the infra.
* Create-CLI.ps1 create only the cursed client, same ase Create-SRV.ps1.
* SRV-Kill.ps1 cease the suffering of the servers.
* ALL-Kill.ps1 cease all the travesty of infrastructure.
## TODO
# TODO
* Integrate SRV-02 creation and role definition.
* Variable isinde Create-SRV.ps1, Create-CLI.ps1.
* Unmount disk on Kill scripts.
## Credit roll
* Sorry to the free-software community for, in a way, increasing the radiance of the Microsoft "hegemony"
* Richard M. Stallman for his work and his wise teachings
* Sylvain Arrambourg, for his teachings and patience.
# Credit roll
* Sorry to the free-software community for, in a way, increasing the dummyradiance of the Microsoft
* Richard M. Stallman for his teachings and his wize-wizardness
* Sylvain Arrambourg, for his teachings.
* Well, of course my familly, beloved ones and my cat.
* Go to hell Microsoft, may you eternally burn and take with you corporate greed and private code.
## Licence
GPLv3 my dudes!
* Fuck Microsoft, may you burn in fire and take with you corporate greed and all privater code.

View File

@ -1,2 +0,0 @@
$cul = "tamere"
d:\scripts\temp\2.ps1

View File

@ -1 +0,0 @@
echo $cul