Compare commits

...

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

5 changed files with 170 additions and 162 deletions

View File

@ -1,6 +1,47 @@
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
$scripts_path = Read-host "Scripts path with trailling slash?"
$vhd_path = Read-host "VHD path with trailling slash?"
$vm_path = Read-Host "VM path with trailling slash?"
$source_path = Read-host "Actual source path with trailling slash?"
$source_srv_name = Read-Host "SRV source disk name with extension?"
$source_cli_name = Read-Host "CLI source disk name with extension?"
$base_srv = Read-Host "SRV base disk name with extension?"
$base_cli = Read-Host "CLI base disk name with extension?"
$base_vhd_path = "${vhd_path}Base\"
### Store them as ENV vars
$env:SCRIPTS_PATH = ${scripts_path}
$env:VHD_PATH = ${vhd_path}
$env:VM_PATH = ${vm_path}
$env:SOURCE_PATH = ${source_path}
$env:SOURCE_SRV_NAME = ${source_srv_name}
$env:SOURCE_CLI_NAME = ${source_cli_name}
$env:BASE_SRV_NAME = ${base_srv}
$env:BASE_CLI_NAME = ${base_cli}
$env:FULL_PATH = ${full_path}
$env:BASE_VHD_PATH = ${base_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

@ -5,184 +5,185 @@ echo "GPLv3"
### Considered as finished. Need improvement VM side.
### Define vars
$scripts_path = d:\scripts
### Adding SRV-01
echo "Adding and configuring SRV-01"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-01.vhdx
$vm_name = "SRV-01"
$switch_name = "Arc-SRV"
$gen = 2
$mem = 1024MB
$min_mem = 512MB
$max_mem = 2048MB
$cpus = 2
$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
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 + ":"
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"
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 ${scripts_path}\Guests\SRV-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"
Dismount-VHD d:\VHD\SRV-01.vhdx
Dismount-VHD "$env:VHD_PATH$vm_name.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
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 'SRV-01' -NewName 'Arc-SRV'
Set-VMNetworkAdapter -VMName 'SRV-01' -Name "Arc-SRV" -DeviceNaming on
Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name"
Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -DeviceNaming on
### Adding SRV-03
echo "Adding and configuring SRV-03"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-03.vhdx
$vm_name = "SRV-01"
$switch_name = "Arc-SRV"
$gen = 2
$mem = 1024MB
$min_mem = 512MB
$max_mem = 2048MB
$cpus = 2
$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
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 + ":"
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"
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 ${scripts_path}\Guests\SRV-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"
Dismount-VHD d:\VHD\SRV-03.vhdx
Dismount-VHD "$env:VHD_PATH$vm_name.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
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 'SRV-03' -NewName 'Bou-LAN'
Set-VMNetworkAdapter -VMName 'SRV-03' -Name "Bou-Lan" -DeviceNaming on
Rename-VMNetworkAdapter -VMName "$vm_name" -NewName "$switch_name"
Set-VMNetworkAdapter -VMName "$vm_name" -Name "$switch_name" -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
$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
$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
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 + ":"
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"
$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 ${scripts_path}\Guests\RTR-01.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"
Dismount-VHD d:\VHD\RTR-01.vhdx
Dismount-VHD "$env:VHD_PATH$vm_name.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
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"
#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
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
echo "Adding and configuring RTR-02"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-02.vhdx
$vm_name = "RTR-02"
$switch_name = "Bou-LAN"
$switch_name2 = "WAN"
$gen = 2
$mem = 1024MB
$min_mem = 512MB
$max_mem = 2048MB
$cpus = 2
$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
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 + ":"
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)
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 ${scripts_path}\Guests\RTR-02.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"
Dismount-VHD d:\VHD\RTR-02.vhdx
Dismount-VHD "$env:VHD_PATH$vm_name.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
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 '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
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
echo "Adding and configuring RTR-03"
cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\RTR-03.vhdx
$vm_name = "RTR-03"
$switch_name = "Aston"
$switch_name3 = "WAN"
$gen = 2
$mem = 1024MB
$min_mem = 512MB
$max_mem = 2048MB
$cpus = 2
$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
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 + ":"
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"
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 ${scripts_path}\Guests\RTR-03.ps1 "${Driveletter}:\Tools\scripts\boot.ps1"
Copy-item "${env:SCRIPTS_PATH}Guests\$vm_name.ps1" "${Drive}\Tools\scripts\boot.ps1"
Dismount-VHD d:\VHD\RTR-03.vhdx
Dismount-VHD $env:VHD_PATH$vm_name.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
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 'RTR-03' -NewName 'WAN'
Set-VMNetworkAdapter -VMName 'RTR-03' -Name "WAN" -DeviceNaming on
Add-VMNetworkAdapter -VMName "RTR-03" -SwitchName "Aston" -Name "Aston" -DeviceNaming on
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"
Start-VM -Name RTR*

View File

@ -1,31 +0,0 @@
# Aston Hyper-V code snipets
## 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.
## Usage
First of all, here be dragons.
The host folder contain all scripts needed for deploying the infra.
* Bootstrap-Hyper-V.ps1 copy the necessary files (diff disks etc) on the desired folders. It will configure automaticaly all aspects to launch VMs on this atrocious Hyper-v.`v1`
* Create-ALL.ps1 create all VMs with adequate parameters to comply with the school pre-defined infrastructure. It consist on 2 server on a separate network that does AD, DNS, DHCP for one and nothing for the other at the time.`v1`
* Create-SRV.ps1 creates only the poor servers, fixed parameters for the moment.
* 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
* 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.
* 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!

View File

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

View File

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