ADOCI/adoci.ps1
2025-06-16 22:58:20 +00:00

66 lines
1.9 KiB
PowerShell

#ps1_sysnative
Try {
#
# Start the logging in the C:\DomainJoin directory
#
Start-Transcript -Path "C:\DomainJoin\stage1.txt"
# Global Variables
$password="P@ssw0rd123!!"
# Set the Administrator Password and activate the Domain Admin Account
#
net user Administrator $password /logonpasswordchg:no /active:yes
# Install the Windows features necessary for Active Directory
# Features
# - .NET Core
# - Active Directory Domain Services
# - Remote Active Directory Services
# - DNS Services
#
Install-WindowsFeature NET-Framework-Core
Install-WindowsFeature AD-Domain-Services
Install-WindowsFeature RSAT-ADDS
Install-WindowsFeature RSAT-DNS-Server
# Create text block for the new script that will be ran once on reboot
#
$addsmodule02 = @"
#ps1_sysnative
Try {
Start-Transcript -Path C:\DomainJoin\stage2.txt
`$password = "P@ssw0rd123!!"
`$FullDomainName = "cruvinelmarcal.corp"
`$ShortDomainName = "cruvinelmarcal"
`$encrypted = ConvertTo-SecureString `$password -AsPlainText -Force
Import-Module ADDSDeployment
Install-ADDSForest ``
-CreateDnsDelegation:`$false ``
-DatabasePath "C:\Windows\NTDS" ``
-DomainMode "WinThreshold" ``
-DomainName `$FullDomainName ``
-DomainNetbiosName `$ShortDomainName ``
-ForestMode "WinThreshold" ``
-InstallDns:`$true ``
-LogPath "C:\Windows\NTDS" ``
-NoRebootOnCompletion:`$false ``
-SysvolPath "C:\Windows\SYSVOL" ``
-SafeModeAdministratorPassword `$encrypted ``
-Force:`$true
} Catch {
Write-Host $_
} Finally {
Stop-Transcript
}
"@
Add-Content -Path "C:\DomainJoin\ADDCmodule2.ps1" -Value $addsmodule02
# Adding the run once job
#
$RunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
set-itemproperty $RunOnceKey "NextRun" ('C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -executionPolicy Unrestricted -File ' + "C:\DomainJoin\ADDCmodule2.ps1")
# End the logging
#
} Catch {
Write-Host $_
} Finally {
Stop-Transcript
}
# Last step is to reboot the local host
Restart-Computer -ComputerName "localhost" -Force