Aston-HyperV-Code/Guests/RTR-03.ps1
Alexandre-Simao d7b8e3f957 Last version before end of week.
Need to refactor routing conf (via netsh) and reboots.
2021-04-23 17:37:49 +02:00

100 lines
2.3 KiB
PowerShell

# Made by Alexandre SIMAO
# GPLv3
# Script to install and configure a Fuckdows Server 2016 as a router
# RTR-03 Only
# Script done
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
### Change the poor machine name
echo "Renaming Computer"
Rename-computer RTR-03
#END
### Rename Adapters by parsing the VM device name
echo "Renaming Computer"
$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 30s"
Sleep 10
### Général IP configure
echo "IP Configuration"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$IPType = "IPv4"
#WAN IP conf
netsh interface ip set address name="WAN" static 192.168.255.254 255.255.255.0
#Aston
netsh interface ip set address name="Aston" DHCP
### 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 ('9.9.9.9') }
#End
### Install Routing and necessary linked roles
echo "Installing Routing and necessary linked roles"
Install-WindowsFeature RemoteAccess, RSAT-RemoteAccess-PowerShell, Routing -IncludeManagementTools
### Install VPN (?)
echo "Install Vpn"
Install-remoteAccess -VpnType Vpn
#End
### Change ZoneAlarm rule to accept incoming ICMP ipv4 probes ###
echo "Allowing ICMPv4 probes"
$Params = @{
"Name" = 'vm-monitoring-icmpv4'
"Action" = 'Allow'
}
Set-NetFirewallRule @Params
#END
### Activating remote-access role
echo "Activating remote-access role"
set-service RemoteAccess -StartupType Automatic
Start-Service RemoteAccess
#End
#netsh -f ./WAN.conf
### Set connection as Private
echo "Setting connection as private"
Set-NetConnectionProfile -networkcategory private
#End
# Add routes
echo "Adding routes"
route add -p 192.168.8.0/24 192.168.255.8
route add -p 192.168.12.0/24 192.168.255.8
route add -p 192.168.128.0/24 192.168.255.128
route add -p 0.0.0.0/0 192.168.255.254
ipconfig /renew
Read-Host "Finished???"