Skip to content

Instantly share code, notes, and snippets.

@daurrutia
Last active June 12, 2021 17:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daurrutia/c5858eefdc5b0d29be793f094598f029 to your computer and use it in GitHub Desktop.
Save daurrutia/c5858eefdc5b0d29be793f094598f029 to your computer and use it in GitHub Desktop.
Windows Server AD Deployment Settings on AWS (DNS, Domain join)
<#
.Synopsis
Joins new Windows server to a Windows domain on AWS
.DESCRIPTION
Sets local DNS entries to DNS server(s) by IP (Set-DnsClientServerAddress)
Enables "Use this connection's DNS suffix in DNS registration" (Set-DnsClient)
Appends domain DNS suffix (WMI)
Adds server to domain in specified OU and renames server (Add-Computer)
.EXAMPLE
Log on to new server
Move/Copy this script to new server
Open script in ISE/editor
Modify target OU path for new server
Save script as .ps1
Run as admin
Enter "ethernet" interface index
Enter IP address(es) of target environment DNS servers
Enter domain name of target domain
Enter desired computer name for the new server
Enter credentials of Enterprise/Domain admin on target domain
Run Restart-Computer
#>
Get-DnsClient
$id = Read-Host "Enter the Interface Index (ex., 7, 3, etc.)"
$dnsIP = Read-Host "Enter the IP address(es) of the primary DNS server (Set-DnsClient) [10.0.1.12, 10.0.1.13]"
$domain = Read-Host "Enter the domain name (ex., corp.company.com, contoso.local, etc.)"
$name = Read-Host "Enter the new computer name (ex., SVR1, DNS01, etc.)"
Set-DnsClientServerAddress -InterfaceIndex $id -ServerAddresses $dnsIP
Set-DnsClient -InterfaceIndex $id -UseSuffixWhenRegistering:$true
$suffixes = 'us-east-1.ec2-utilities.amazonaws.com', 'ec2.internal', $domain
$class = [wmiclass]'Win32_NetworkAdapterConfiguration'
$class.SetDNSSuffixSearchOrder($suffixes)
# Modify OU path before run
Add-Computer -DomainName $domain -OUPath "OU=servers,DC=corp,DC=company,DC=com" -NewName $name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment