Assistance at your fingertips...

PS Script to Promote 2019 Server to RWDC

Wow, did this work well. Now that DCPROMO is no onger available, you need to have a mean to promote a DC and go do something else while it runs (especially if it’s on another continent). This script does just that and man does it save time!

Writing helpful scripts, every day… that's me!

'Promote-RWDC-Locally-Prompt.ps1'
# Set-PSCredential.ps1
# Set variable for cred and store for using script over and over from your -da account
# You can use this code in your profile to call $PSCredential from any script too

#Remove when changed
#rm -force $env:USERPROFILE\mycredential.xml
$credFile = "$env:USERPROFILE\mycredential.xml"  
  
if(Test-Path $credFile){
    $PSCredential = Import-Clixml $credFile  
}  
else{  
    $myusername = Read-host -Prompt "What logon name to runas? (like JoeyG-Admin)"
    $PSCredential = Get-Credential -Credential "$myusername@NoneYaBidness.com"  
    $PSCredential | Export-Clixml $credFile  
}
#Once you type in the password ONCE you just use $PSCredential for the '-Credential' entry eanywhere in the script

$day = get-date -format 'yyyMMdd'
mkdir D:\PowerShell -ea SilentlyContinue
set-location d:\powershell
if (!(test-path d:\powershell\input)){New-Item -EA Ignore -WA Ignore -ItemType directory -Path d:\powershell\input} 
[System.Environment]::SetEnvironmentVariable("PSModulePath", "d:\powershell\Modules;" + $Env:PSModulePath)
Get-WindowsFeature RSAT-AD-PowerShell -verbose
Add-WindowsFeature RSAT-AD-PowerShell -verbose  -ea Inquire
Add-WindowsFeature -Name "DNS" -IncludeAllSubFeature:$True -IncludeManagementTools:$True  -ea Inquire -LogPath "D:\powershell\log\$day-RWDCPromo.log" -verbose
Add-WindowsFeature -Name "RSAT-DNS-Server" -IncludeAllSubFeature:$True -IncludeManagementTools:$True -ea Inquire -LogPath "D:\powershell\log\$day-RWDCPromo.log" -verbose
Add-WindowsFeature -Name "RSAT-AD-Tools" -IncludeAllSubFeature:$True -IncludeManagementTools:$True -ea Inquire -LogPath "D:\powershell\log\$day-RWDCPromo.log" -verbose
# Only install the necessary features for an RWDC
Add-WindowsFeature -Name "AD-Domain-Services" -IncludeManagementTools:$true  -ea Inquire -LogPath "D:\powershell\log\$day-RWDCPromo.log"
# Install the management tools for AD-Domain-Services
Get-WindowsFeature RSAT-ADDS-Tools -verbose
Add-WindowsFeature -Name "RSAT-ADDS-Tools" -IncludeAllSubFeature:$True -IncludeManagementTools:$True -ea Inquire -LogPath "D:\powershell\log\$day-RWDCPromo.log"
"Right here you need to add the DNS forwarders manually by adding the IPs in the list"
Pause
$server = "$env:COMPUTERNAME"
$user = "$server\Administrator"
# Get the DSRM password - WRITE IT DOWN!!!
$cred = Get-Credential -UserName $user -Message "Enter your DSRM password"
$dsrmPassword = ConvertTo-SecureString -String "$cred" -AsPlainText -Force
$Sitename = "What Site are you installing into? (Like NYCC)"
Install-ADDSDomainController `
-Verbose `
-LogPath "D:\powershell\log\$day-RWDCPromo.log" `
-NoDnsOnNetwork:$False `
-NoGlobalCatalog:$False `
-ReadOnlyReplica:$False `
-CreateDnsDelegation:$false `
-CriticalReplicationOnly:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainName "domain.forest.root" `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SiteName "$Sitename" `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true `
-SafeModeAdministratorPassword $dsrmPassword `
-Confirm `
-ErrorAction Inquire `
-SkipPreChecks:$false `
-Credential $PScredential `

Posted

in

, , ,

by