Last active
November 1, 2024 18:29
-
-
Save Soulsender/58a3d8bb5e658dc757aa3b6d8227c6a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Write-Host "YOU MUST SET YOUR HOSTNAME BEFORE CONTINUING" -ForegroundColor Red | |
| Write-Host "IF THIS IS A HYPER-V HOST YOU MUST SET YOUR ADAPTER TO INTERNAL IF NEEDED" -ForegroundColor Red | |
| $response = Read-Host -Prompt "Your hostname is currently $((Get-ComputerInfo).CsName). Is this correct? (Y/n)" | |
| if ($response -eq 'Y' -or $response -eq 'y') { | |
| Write-Host "Continuing Install..." -ForegroundColor Green | |
| } elseif ($response -eq 'N' -or $response -eq 'n') { | |
| Write-Host "Cancelling Installation." -ForegroundColor Red | |
| exit 0 | |
| } else { | |
| Write-Host "Invalid response. Please enter Y or N." | |
| exit 0 | |
| } | |
| $ipAddr = Read-Host -Prompt "IPv4 Address" | |
| $prefix = Read-Host -Prompt "CIDR subnet mask (no /)" | |
| $gateway = Read-Host -Prompt "Default Gateway" | |
| $dnsServer = Read-Host -Prompt "DNS Server" | |
| # $name = Read-Host -Prompt "PC Name" | |
| try { | |
| New-NetIPAddress -Ipaddress $ipAddr -PrefixLength $prefix -DefaultGateway $gateway -InterfaceAlias "Ethernet" | |
| } catch { | |
| Set-NetIPAddress -Ipaddress $ipAddr -PrefixLength $prefix -InterfaceAlias "Ethernet" | |
| } | |
| Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses $dnsServer | |
| # Rename-Computer -NewName $name | |
| # prompt to join AD domain | |
| $response = Read-Host -Prompt "Join AD Domain? (Y/n)" | |
| if ($response -eq 'Y' -or $response -eq 'y') { | |
| $domainName = Read-Host -Prompt "Domain: " | |
| Add-Computer -DomainName $domainName -Credential (Get-Credential) -Restart | |
| } elseif ($response -eq 'N' -or $response -eq 'n') { | |
| Write-Host "Not joining domain." | |
| } else { | |
| Write-Host "Invalid response. Please enter Y or N." | |
| } | |
| # prompt to become DC | |
| $response = Read-Host -Prompt "Set as Domain Controller? (Y/n)" | |
| if ($response -eq 'Y' -or $response -eq 'y') { | |
| $domainName = Read-Host -Prompt "Domain: " | |
| $netbiosName = ($domainName -split '\.')[0].ToUpper() | |
| Install-WindowsFeature -name AD-Domain-Services -IncludeManagementTools | |
| Install-ADDSForest -DomainName $domainName -DomainNetbiosName $netbiosName -InstallDNS -Force | |
| } elseif ($response -eq 'N' -or $response -eq 'n') { | |
| Write-Host "Not becoming Domain Controller." | |
| } else { | |
| Write-Host "Invalid response. Please enter Y or N." | |
| } | |
| Write-host "Script Complete!" -ForegroundColor Green | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment