Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewbbrown/1c81a3034e3a8407ffb504bccab1f8eb to your computer and use it in GitHub Desktop.
Save andrewbbrown/1c81a3034e3a8407ffb504bccab1f8eb to your computer and use it in GitHub Desktop.
This has all of the AD and DNS Zone Features taken out...
try {
# Boxstarter options
$Boxstarter.RebootOk=$true
$Boxstarter.NoPassword=$false # Is this a machine with no logon password?
$Boxstarter.AutoLogin=$true
# Install Remote Server Administration Tools
Write-BoxstarterMessage "Installing Remote Server Administration Tools - Role Tools"
#This one is a little overkill and includes a lot of extra features... use Get-WindowsFeature to see all included
#Get-WindowsFeature RSAT | Install-WindowsFeature -IncludeAllSubFeature
Get-WindowsFeature RSAT-Role-Tools | Install-WindowsFeature -IncludeAllSubFeature -IncludeManagementTools
Get-WindowsFeature AD-Domain-Services | Install-WindowsFeature -IncludeManagementTools -IncludeAllSubFeature
Get-WindowsFeature Web-Mgmt-Service | Install-WindowsFeature -IncludeAllSubFeature -IncludeManagementTools
Function Set-IPAddress {
param (
[string]$Name = "Ethernet0",
[IPAddress]$IP = "10.67.36.4",
[string] $CIDR = 24, # This means subnet mask = 255.255.255.0,
[string]$Gateway = "10.67.36.10",
[string]$Dns = "127.0.0.1,10.67.36.10",
[string]$IPType = "IPv4",
[string]$Type = "Static",
[string]$NewName = "Management"
)
# Retrieve the network adapter that you want to configure
$adapter = Get-NetAdapter | ? {$_.Name -eq $Name}
if ($Type -eq "Static") {
# Remove any existing IP, gateway from our ipv4 adapter
If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) {
Write-Host "Removing existing IP"
$adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false
}
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) {
Write-Host "Removing existing gateway"
$adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false
}
# Configure the IP address and default gateway
Write-Host "Configuring new IP"
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $CIDR `
-DefaultGateway $Gateway
# Configure the DNS client server IP addresses
Write-Host "Configuring new gateway"
$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS
}
else {
$interface = $adapter | Get-NetIPInterface -AddressFamily $IPType
If ($interface.Dhcp -eq "Disabled") {
# Remove existing gateway
Write-Host "Removing existing gateway"
If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) {
$interface | Remove-NetRoute -Confirm:$false
}
# Enable DHCP
Write-Host "Enabling DHCP on interface"
$interface | Set-NetIPInterface -DHCP Enabled
# Configure the DNS Servers automatically
Write-Host "Enabling automatic DNS"
$interface | Set-DnsClientServerAddress -ResetServerAddresses
}
}
Write-Host "Restarting adapter"
$adapter | Restart-NetAdapter
$adapter | Rename-NetAdapter -NewName $NewName
$adapter = Get-NetAdapter | ? {$_.Name -eq $NewName}
$adapter | Restart-NetAdapter
}
Set-IPAddress -Name "Ethernet0" -NewName "Management" -IP "10.67.36.4" -Gateway "10.67.36.10" -Dns "127.0.0.1,10.67.36.10" -Type "Static" -IPType "IPv4"
# Rename Computer
$ServerName = "HL2-DC1"
$HostName = $($env:computername).ToUpper()
if ($HostName -ne $ServerName) { Rename-Computer -NewName $ServerName}
if (Test-PendingReboot) { Invoke-Reboot }
# Install DNS
Write-BoxstarterMessage "Installing DNS Server Windows Feature!!"
#Install-WindowsFeature 'DNS' -IncludeManagementTools
Get-WindowsFeature DNS | Install-WindowsFeature -IncludeAllSubFeature
if (Test-PendingReboot) { Invoke-Reboot }
# Install AD
Write-BoxstarterMessage "Installing AD Server Windows Feature!!"
##Install-WindowsFeature 'AD-Domain-Services' -IncludeAllSubFeature -IncludeManagementTools
Get-WindowsFeature AD-Domain-Services | Install-WindowsFeature -IncludeAllSubFeature -IncludeManagementTools
if (Test-PendingReboot) { Invoke-Reboot }
#Enable AD
# Installing ADDS Forest that is DNS connected
Write-BoxstarterMessage "Creating Active Directory Forest!!"
$newDomainName="foobar99.local"
$newDomainNetBios="foobar99"
try{ $IsAdForestOnline = Get-ADForest -Server $newDomainName | Select -ExpandProperty "Name" }catch{ $IsAdForestOnline = $null }
if($IsAdForestOnline -ne "foobar99.local")
{
Write-BoxstarterMessage "AD Forest not detected - sleeping for 120 seconds to allow services to come online and then installing AD Forest";
Start-Sleep -s 120;
$newDomainName="foobar99.local"
$newDomainNetBios="foobar99"
Install-ADDSForest -DomainName $newDomainName -InstallDns -DomainNetbiosName $newDomainNetBios -SafeModeAdministratorPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force) -Force
}
##savingjustincase##Install-ADDSForest -DomainName $newDomainName -InstallDns -DomainNetbiosName $newDomainNetBios -SafeModeAdministratorPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force) -Force
## did not work becasue DNS delegation does not exist...
## Install-ADDSForest -DomainName $newDomainName -CreateDNSDelegation -DomainNetbiosName $newDomainNetBios -SafeModeAdministratorPassword (ConvertTo-SecureString "P@ssword1" -AsPlainText -Force) -Force
if (Test-PendingReboot) { Invoke-Reboot }
Write-BoxstarterMessage "Machine is complete!"
} catch {
Write-ChocolateyFailure 'Boxstarter Error: ' $($_.Exception.Message)
throw
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment