Quickly creating a new Windows domain using PowerShell (for testing purposes, etc.)

Posted: (EET/GMT+2)

 

I often find myself firing up new virtual machines to simulate a small network. For instance, earlier this week I needed to build a simple network of three virtual machines: one Windows Server 2012 R2 domain controller, one Windows Server 2012 R2 web server and one Windows 8.1 client.

Now, one of the hurdles in installing the domain controller is to promote a regular server to a domain controller. This can be done in a pretty straightforward fashion using the Server Managed and adding the Active Directory Directory Services role and then running "dcpromo", but there's also an alternative to this using PowerShell: the Install-ADDSForest cmdlet.

Without much ado, you can run this command like this:

Import-Module ADDSDeployment
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012R2" `
-DomainName "mydomain.test" `
-DomainNetbiosName "MYDOMAIN" `
-ForestMode "Win2012R2" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true

For more information about this new command in Windows Server 2012 R2, check out the documentation. Note that the backtick character ` is the line continuation character in PowerShell.

Faster hacking!