Aston-HyperV-Code/Guests/SRV-03.ps1

144 lines
4.1 KiB
PowerShell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Alexandre Simao
# GPL v3
# SRV-03 ONLY
# asrc.dev,asrc.local,dev.asrc.local
# TODO:
echo "Shamefully made by Alexandre Simao. Pardon-me M. Stallman"
### Rename this piece of garbage
echo "Changing Computer's name"
Rename-computer "SRV-03"
# 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="Bou-LAN" static 192.168.128.1 255.255.255.0 192.168.128.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') }
### 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
### Add routes for RTR-03
echo "Add routes for RTR-03"
route add -p 192.168.8.0/24 192.168.128.254
route add -p 192.168.12.0/24 192.168.128.254
route add -p 192.168.255.0/24 192.168.128.254
route add -p 0.0.0.0/0 192.168.128.254
# END
### Installing and configuring DNS role
# Install and configure DNS server
Install-WindowsFeature -Name DNS -IncludeManagementTools -includeallsubfeature
#Add-DnsServerPrimaryZone -NetworkID 192.168.128.0/24 -ZoneFile “192.168.128.1.in-addr.arpa.dns” # Zone secondaire
#Create asrc.dev
Add-DnsServerPrimaryZone -ResponsiblePerson "bol@loc.ks" -DynamicUpdate None -ZoneFile asrc.dev.dns -Name asrc.dev
Set-DnsServerPrimaryZone -ComputerName SRV-03 -Name asrc.dev -SecureSecondaries "NoTransfer"
$ns = Get-DnsServerResourceRecord -ZoneName asrc.dev -RRType NS
$nsnew = $ns.Clone()
$nsnew.RecordData.NameServer = "srv-03.asrc.local"
Set-DnsServerResourceRecord -ZoneName asrc.dev -NewInputObject $nsnew -OldInputObject $ns
$soa = Get-DnsServerResourceRecord -ZoneName asrc.dev -RRType Soa
$soanew = $soa.Clone()
$soanew.RecordData.PrimaryServer = "srv-03.asrc.local"
$soanew.RecordData.ExpireLimit = (New-TimeSpan -Days 4)
Set-DnsServerResourceRecord -ZoneName asrc.dev -NewInputObject $soanew -OldInputObject $soa
#Create dev.asrc.local
Add-DnsServerPrimaryZone -ResponsiblePerson "bol@loc.ks" -DynamicUpdate None -ZoneFile dev.asrc.local.dns -Name dev.asrc.local
Set-DnsServerPrimaryZone -ComputerName SRV-03 -Name dev.asrc.local -SecureSecondaries "NoTransfer"
#Create reverse lookup Zone
Add-DnsServerPrimaryZone -NetworkID "192.168.0.0/16" -Zonefile "168.192.in-addr.arpa.dns"
Add-DnsServerSecondaryZone -NetworkID "192.168.0.0/16" -Zonefile "168.192.in-addr.arpa.dns" -MasterServers 192.168.8.1
#Rename SOA+NS Direct
$ns = Get-DnsServerResourceRecord -ZoneName dev.asrc.local -RRType NS
$nsnew = $ns.Clone()
$nsnew.RecordData.NameServer = "srv-03.asrc.local"
Set-DnsServerResourceRecord -ZoneName dev.asrc.local -NewInputObject $nsnew -OldInputObject $ns
$soa = Get-DnsServerResourceRecord -ZoneName dev.asrc.local -RRType Soa
$soanew = $soa.Clone()
$soanew.RecordData.PrimaryServer = "srv-03.asrc.local"
$soanew.RecordData.ExpireLimit = (New-TimeSpan -Days 4)
Set-DnsServerResourceRecord -ZoneName dev.asrc.local -NewInputObject $soanew -OldInputObject $soa
Add-DnsServerForwarder -IPAddress 9.9.9.9 -PassThru # Forward
Add-DnsServerResourceRecordA -Name "SRV-03" -ZoneName "dev.asrc.local" -IPv4Address "192.168.128.1" -TimeToLive 01:00:00
Add-DnsServerResourceRecordA -Name "SRV-03" -ZoneName "asrc.dev" -IPv4Address "192.168.128.1" -TimeToLive 01:00:00
#Add DNS secondary zone for asrc.local
Add-DnsServerSecondaryZone -Name "asrc.local" -ZoneFile "asrc.local.dns" -MasterServers 192.168.8.1
Start-DnsServerZoneTransfer -Name "asrc.local" -Fulltransfer
Read-Host "Finished?"
Restart-Computer