Create Domain Controller using PowerShell Direct

I have a new Hyper-V server for my labs and I need to create a new virtual environment as soon as possible.

After I finished installing Windows patches and other software, I make an image using sysprep.

Then, I created a new virtual machine using my new Windows 2019 image.

I chose to use PowerShell Direct to create a new Domain Controller for my new virtual infrastructure.

From PowerShell ISE, I ran the following commands:

  1. To connect to the guest VM

$vm = ‘DC01’

$cred = Get-Credential -Credential “$vm\Administrator”

$s = New-PSSession -VMName $vm -Credential $cred

  1. 2. To get Windows Features regarding the Active Directory & DNS

$sb = {Get-WindowsFeature -Name AD*, DNS }

Invoke-Command -Session $s -ScriptBlock $sb |

select DisplayName, Name, InstallState

  1. 3. To install the Roles and Features for ADDS & DNS

$sb = {Install-WindowsFeature -Name AD-Domain-Services, DNS -IncludeAllSubFeature -IncludeManagementTools -Restart}

Invoke-Command -Session $s -ScriptBlock $sb

  1. 4. To promote to Domain Controller

$sb = {

Install-ADDSForest  -ForestMode 7 -DomainMode 7 `

-DomainName ‘gklonislab.me’  -DomainNetbiosName ‘gklonislab’ `

-InstallDns:$true -CreateDnsDelegation:$false `

-DatabasePath ‘C:\Windows\NTDS’ -LogPath ‘C:\Windows\NTDS’ `

-SysvolPath ‘C:\Windows\SYSVOL’ `

-Force:$true

}

Invoke-Command -Session $s -ScriptBlock $sb

You’ll be prompted twice for the Safe Mode Administrator password.

When the script finished you will get the result below and the server restarts automatically.

PSComputerName : DC01

 RunspaceId     : 5a3b647f-1aa0-4f58-8b13-67d00d7ddde4

 Message        : Operation completed successfully

 Context        : DCPromo.General.1

 RebootRequired : False

 Status         : Success

Leave a Reply