Last active
November 1, 2025 14:06
-
-
Save p4yl0ad/ce3aeedef33f37443e683afb361fde78 to your computer and use it in GitHub Desktop.
QuickDC-VMWare.ps1
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
| <# | |
| .Synopsis | |
| Create 'FEDERATED.LOCAL' domain on domaincontroller | |
| .DESCRIPTION | |
| Install Active Directory with PowerShell, along with DNS and DHCP to create a domain controller | |
| Tested on Windows Server 2019 Version 1809 (OS Build 17763.5329) | |
| .EXAMPLE | |
| . .\QuickDC-VMWare.ps1 | |
| Description | |
| --------------------------------------- | |
| Execute the installer to configure the current Windows Server 2019 | |
| #> | |
| $config = @' | |
| $script = "QuickDC" | |
| $hostname = "DC0001" | |
| $domain = "FEDERATED.LOCAL" | |
| $netbios = "FED" | |
| $username = "Administrator" | |
| $password = "Password123!" | |
| $safemodepassword = "@SafeModeAdministratorPassword1@" | |
| $interface = "Ethernet0" | |
| $ipAddr = "192.168.154.100" | |
| $gateway = "192.168.154.2" # VMWare default | |
| $lowprivuser = 'lowpriv' | |
| $lowprivpass = 'Password123!' | |
| $compobject1 = 'AYYLMAO1' | |
| $compobject2 = 'AYYLMAO2' | |
| $dnsOne = "127.0.0.1" # IP Address of this DC | |
| $dnsTwo = "1.1.1.1" | |
| $taskname = "ContinueAfterReboot" | |
| $tasknameTwo = "ContinueAfterRebootTwo" | |
| $transcriptOne = "C:\"+$script+"-VMWare_part1.log" | |
| $transcriptTwo = "C:\"+$script+"-VMWare_part2.log" | |
| $transcriptThree = "C:\"+$script+"-VMWare_part3.log" | |
| '@ | |
| Write-Host "[+] writing config.ps1" | |
| $config | Out-File -FilePath C:\config.ps1 | |
| Write-Host "[+] importing config.ps1" | |
| . C:\config.ps1 | |
| Write-Host "[+] Configuring autologin" | |
| $RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' | |
| Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String | |
| Set-ItemProperty $RegistryPath 'AutoLogonCount' -Value "99999" -Type String | |
| Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "$username" -type String | |
| Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "$password" -type String | |
| $ErrorActionPreference = "Stop" | |
| Write-Host "[+] starting transcript One" | |
| Start-Transcript $transcriptOne | |
| # Initial actions | |
| Write-Host "[*] Performing initial actions before reboot..." | |
| Write-Host "[+] Renaming computer to" $hostname | |
| Rename-Computer -NewName $hostname | |
| Write-Host '# Disable QuickEdit and InsertMode' | |
| Set-ItemProperty -Path 'HKCU:\Console' -Name 'QuickEdit' -Value 0 | |
| Set-ItemProperty -Path 'HKCU:\Console' -Name 'InsertMode' -Value 0 | |
| Write-Host "[+] Uninstalling Windows-Defender" | |
| Uninstall-WindowsFeature -Name Windows-Defender | |
| Write-Host "[+] Configuring firewall for Domain, Public and Private to be disabled" | |
| Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False | |
| Write-Host "[+] Disabling WindowsErrorReporting" | |
| Disable-WindowsErrorReporting | |
| Write-Host "[+] Disabling DHCP" | |
| Set-NetIPInterface -Dhcp Disabled | |
| Write-Host "[+] Disabling IPV6" | |
| Disable-NetAdapterBinding -Name $interface -ComponentID ms_tcpip6 | |
| Write-Host "[+] Assigning" + $interface + "with IP Address" + $ipAddr + "and gateway" + $gateway | |
| New-NetIPAddress ` | |
| -InterfaceAlias $interface ` | |
| -IPAddress $ipAddr ` | |
| -AddressFamily IPv4 ` | |
| -PrefixLength 24 ` | |
| -DefaultGateway $gateway | |
| Write-Host "[+] Installing AD-Domain-Services with management tools" | |
| Install-WindowsFeature AD-Domain-Services –IncludeManagementTools -Verbose | |
| Write-Host "[+] Installing DNS with management tools" | |
| Install-WindowsFeature DNS -IncludeManagementTools -Verbose | |
| Write-Host "[+] Setting DNS" | |
| Set-DnsClientServerAddress -InterfaceAlias $interface -ServerAddresses $dnsOne,$dnsTwo | |
| $scriptBlock = { | |
| . C:\config.ps1 | |
| Write-Host "[+] Starting transcript Two" | |
| Start-Transcript $transcriptTwo | |
| Write-Host "[+] Importing ADDSDeployment" | |
| Import-Module ADDSDeployment | |
| Write-Host "[+] Running Install-ADDSForest for domain" $domain "with NETBIOS name of" $netbios | |
| $Secure_String_Pwd = ConvertTo-SecureString $safemodepassword -AsPlainText -Force | |
| Install-ADDSForest ` | |
| -DomainName $domain ` | |
| -DomainNetBiosName $netbios ` | |
| -InstallDns:$true ` | |
| -NoRebootOnCompletion:$true ` | |
| -SafeModeAdministratorPassword:$Secure_String_Pwd ` | |
| -Force | |
| $scriptBlockTwo = { | |
| Write-Host "[+] Importing config.ps1" | |
| . C:\\config.ps1 | |
| $ErrorActionPreference = "Stop" | |
| Write-Host "[+] Starting transcript Three" | |
| Start-Transcript $transcriptThree | |
| Write-Host "[+] Running Get-ADDomainController -Discover" | |
| Get-ADDomainController -Discover | |
| net user $lowprivuser $lowprivpass $ /add /dom | |
| net computer \\$compobject1 /ADD | |
| net computer \\$compobject2 /ADD | |
| Write-Host "[+] Running net users /dom" | |
| net users /dom | |
| Write-Host "[+] Running Get-Service adws,kdc,netlogon,dns" | |
| Get-Service adws,kdc,netlogon,dns | |
| Write-Host "[+] Running Get-SMBShare" | |
| Get-SMBShare | |
| Write-Host "[+] Running netdom /query FSMO" | |
| netdom /query FSMO | |
| Write-Host "[+] Unregistering previous scheduled task" | |
| Unregister-ScheduledTask -TaskName $tasknameTwo -Confirm:$false | |
| Write-Host "[+] Stopping transcript" | |
| Stop-Transcript | |
| } | |
| Write-Host "[+] Converting script block to a Base64 encoded string to pass it to the scheduled task" | |
| $encodedCommandTwo = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($scriptBlockTwo.ToString())) | |
| Write-Host "[+] Creating the scheduled task" | |
| $actionTwo = New-ScheduledTaskAction ` | |
| -Execute 'Powershell.exe' ` | |
| -Argument "-ExecutionPolicy Bypass -NoP -NoExit -EncodedCommand $encodedCommandTwo" ` | |
| -WorkingDirectory "C:\\ProgramData" | |
| $triggerTwo = New-ScheduledTaskTrigger -AtLogon | |
| $principalTwo = New-ScheduledTaskPrincipal -UserID "Administrator" -RunLevel Highest | |
| Register-ScheduledTask ` | |
| -Action $actionTwo ` | |
| -Principal $principalTwo ` | |
| -Trigger $triggerTwo ` | |
| -TaskName $tasknameTwo ` | |
| -Description "My task to continue script execution after reboot" | |
| Write-Host "[+] Unregistering previous scheduled task" | |
| Unregister-ScheduledTask -TaskName $taskname -Confirm:$false | |
| Write-Host "[+] DA autologin" | |
| $RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' | |
| Set-ItemProperty $RegistryPath 'AutoAdminLogon' -Value "1" -Type String | |
| Set-ItemProperty $RegistryPath 'AutoLogonCount' -Value "99999" -Type String | |
| Set-ItemProperty $RegistryPath 'DefaultUsername' -Value "$username" -type String | |
| Set-ItemProperty $RegistryPath 'DefaultDomain' -Value "$domain" -type String | |
| Set-ItemProperty $RegistryPath 'DefaultPassword' -Value "$password" -type String | |
| Write-Host "[+] Stopping transcript" | |
| Stop-Transcript | |
| # Read-Host -Prompt "Press any key to continue" | |
| Write-Host "[+] Restarting" | |
| Restart-Computer -Force | |
| } | |
| Write-Host "[+] Converting script block to a Base64 encoded string to pass it to the scheduled task" | |
| $encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($scriptBlock.ToString())) | |
| Write-Host "[+] Creating the scheduled task" | |
| $action = New-ScheduledTaskAction ` | |
| -Execute 'Powershell.exe' ` | |
| -Argument "-ExecutionPolicy Bypass -NoP -NoExit -EncodedCommand $encodedCommand" | |
| $trigger = New-ScheduledTaskTrigger -AtLogon | |
| $principal = New-ScheduledTaskPrincipal -UserID "Administrator" -RunLevel Highest | |
| Register-ScheduledTask ` | |
| -Action $action ` | |
| -Principal $principal ` | |
| -Trigger $trigger ` | |
| -TaskName $taskname ` | |
| -Description "My task to continue script execution after reboot" | |
| Write-Host "[+] Stopping transcript" | |
| Stop-Transcript | |
| # Read-Host -Prompt "Press any key to continue" | |
| Write-Host "[+] Restarting" | |
| Restart-Computer -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment