From 695e181d53035a6e090a99876dc3aca111e862af Mon Sep 17 00:00:00 2001 From: Alexandre Simao Date: Mon, 28 Jun 2021 15:25:53 +0200 Subject: [PATCH] Feat: Add bootstrap script --- Guests/SRV-02.ps1 | 69 ++++++++++++++++++++++++++++++++++++++ Host/ALL-Kill.ps1 | 10 ++++++ Host/Bootstrap-Hyper-V.ps1 | 6 ++++ Host/Create-SRV.ps1 | 33 ++++++++++++++++++ Memo.ps1 | 3 ++ 5 files changed, 121 insertions(+) create mode 100644 Guests/SRV-02.ps1 create mode 100644 Host/Bootstrap-Hyper-V.ps1 diff --git a/Guests/SRV-02.ps1 b/Guests/SRV-02.ps1 new file mode 100644 index 0000000..5b1f19d --- /dev/null +++ b/Guests/SRV-02.ps1 @@ -0,0 +1,69 @@ +# Alexandre Simao +# GPL v3 + +# SRV-02 ONLY +# asrc.local domain + +# TODO: Delegation + +echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman" + +### Rename this piece of garbage + +echo "Changing Computer's name" +Rename-computer "SRV-02" +# End + +### Rename interfaces by parsing VM device name + +echo "Renaming adapters" +$adapts = Get-NetAdapter +foreach ($adapt in $adapts) { +$HVName = (Get-NetAdapterAdvancedProperty -name $adapt.name -DisplayName "Hyper-v Network Adapter Name").DisplayValue +Rename-Netadapter -name $adapt.name -NewName $HVName +} +#End + +# Pausing to let things settle + +echo "Sleeping 10s" +Sleep 10 + +### Général IP configure +# echo "IP configuration" + +#Arc-SRV + +netsh interface ip set address name="Arc-SRV" static 192.168.8.2 255.255.255.0 192.168.8.254 + +### DNS Conf for all InterfaceAlias ### + +echo "DNS Conf" +foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('192.168.8.1,192.168.128.1') } + +### Install the DHCP role (Management tools if you love Metrosexual UI) + +echo "Installing DHCP role" +Install-WindowsFeature DHCP -IncludeManagementTools + +#END + +### Setting connection as Private + +echo "Setting connection as Private" +Set-NetConnectionProfile -NetworkCategory Private + +### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes + +echo "Allowing ICMPv4 probes" +$Params = @{ + "Name" = 'vm-monitoring-icmpv4' + "Action" = 'Allow' +} + +Set-NetFirewallRule @Params +# END + + +Read-Host "Finished?" +Restart-Computer diff --git a/Host/ALL-Kill.ps1 b/Host/ALL-Kill.ps1 index 6e2f278..22976fd 100644 --- a/Host/ALL-Kill.ps1 +++ b/Host/ALL-Kill.ps1 @@ -3,5 +3,15 @@ Stop-VM SRV* -turnoff Remove-VM RTR* -Force Remove-VM SRV* -Force +#Dismount-VHD –Path d:\VHD\SRV-01.vhdx +#Dismount-VHD –Path d:\VHD\SRV-02.vhdx +#Dismount-VHD –Path d:\VHD\SRV-03.vhdx +#Dismount-VHD –Path d:\VHD\RTR-01.vhdx +#Dismount-VHD –Path d:\VHD\RTR-02.vhdx +#Dismount-VHD –Path d:\VHD\RTR-03.vhdx +#Dismount-VHD –Path d:\VHD\CLI-01.vhdx +#Dismount-VHD –Path d:\VHD\CLI-02.vhdx +#Dismount-VHD –Path d:\VHD\CLI-03.vhdx + del d:\VHD\RTR* del d:\VHD\SRV* diff --git a/Host/Bootstrap-Hyper-V.ps1 b/Host/Bootstrap-Hyper-V.ps1 new file mode 100644 index 0000000..63a8279 --- /dev/null +++ b/Host/Bootstrap-Hyper-V.ps1 @@ -0,0 +1,6 @@ +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 diff --git a/Host/Create-SRV.ps1 b/Host/Create-SRV.ps1 index 05e7a42..7af5864 100644 --- a/Host/Create-SRV.ps1 +++ b/Host/Create-SRV.ps1 @@ -30,6 +30,39 @@ echo "Configuring adapters" Rename-VMNetworkAdapter -VMName 'SRV-01' -NewName 'Arc-SRV' Set-VMNetworkAdapter -VMName 'SRV-01' -Name "Arc-SRV" -DeviceNaming on +### Adding SRV-02 + +echo "Adding and configuring SRV-02" +cp D:\VHD\Base\Base_SRV_diff.vhdx D:\VHD\SRV-02.vhdx + +$Lettre = Mount-VHD -Path "d:\VHD\SRV-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\SRV-02.ps1 "${Driveletter}:\Tools\scripts\boot.ps1" + +Dismount-VHD d:\VHD\SRV-02.vhdx + +$vms = @{ + + Name = "SRV-02" + Generation = '2' + MemoryStartupBytes = 1024Mb + VHDPath = "d:\VHD\SRV-02.vhdx" + SwitchName = "Arc-SRV" +} + +New-VM @vms +Set-VMMemory SRV-02 -DynamicMemoryEnabled $true -MinimumBytes 512MB -StartupBytes 1024MB -MaximumBytes 2GB +Set-VM -Name SRV-02 -ProcessorCount 2 + +echo "Configuring adapters" +Rename-VMNetworkAdapter -VMName 'SRV-02' -NewName 'Arc-SRV' +Set-VMNetworkAdapter -VMName 'SRV-02' -Name "Arc-SRV" -DeviceNaming on + + ### Adding SRV-03 echo "Adding and configuring SRV-03" diff --git a/Memo.ps1 b/Memo.ps1 index 734fa2a..43e6d38 100644 --- a/Memo.ps1 +++ b/Memo.ps1 @@ -84,3 +84,6 @@ Start-Sleep -Seconds 5 #Replicate the Forwardlookup zones into two additional Public DNS servers Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer1 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile "$DomainNames.dns" Add-DnsServerSecondaryZone -ComputerName $SecondaryDNSServer2 -MasterServers [System.Net.Dns]::GetHostAddresses($PrimaryDNSServer).IPAddressToString -Name $DomainNames -ZoneFile "$DomainNames.dns" + + +Get-WindowsCapability -name "*RSAT*" -online|Add-WindowsCapability -online