PS: Setup A DC Using HyperV

less than 1 minute read

Description:

Follow this guide to install a domain controller using Hyper-V Powershell commands

To Resolve:

  1. Create a Hyper-V Switch with Bridged Networking
# Install the entire Hyper-V stack (hypervisor, services, and tools)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All

# Install the Hyper-V Switch
$net = Get-NetAdapter -Name 'Ethernet'
New-VMSwitch -Name "External VM Switch" -AllowManagementOS $True -NetAdapterName $net.Name
  1. Create Domain Controller
$params = @{
	Name               = "DC"
	MemoryStartupBytes = "2147483648"
	Generation         = "2"
	SwitchName         = "VMNetwork"
	NewVHDSizeBytes    = "21474836480"
	NewVHDPath         = "c:\vms\dc.vhdx"
}
New-VM @params
Set-VM -Name DC -ProcessorCount 2
Add-VMDvdDrive -VMName DC
Set-VMDvdDrive -VMName DC -Path C:\iso\server2016.ISO
Set-VMFirmware -VMName DC -FirstBootDevice $(Get-VMDvdDrive -VMName DC)
Start-VM -Name DC
  1. After OS install:
$params = @{
	InterfaceAlias = "Ethernet"
	IPAddress      = "192.168.1.100"
	PrefixLength   = "24"
	DefaultGateway = "192.168.1.254"
} 
New-NetIPAddress @params
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 192.168.1.254
Rename-Computer -NewName DC -Restart
  1. Adding the role
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
$params = @{
	DomainName                    = "gdub.test"
	DomainNetbiosName             = "gdub"
	DomainMode                    = "Default"
	DatabasePath                  = "C:\Windows\NTDS"
	CreateDnsDelegation           = $false
	ForestMode                    = "Default"
	InstallDns                    = $true
	LogPath                       = "C:\Windows\NTDS"
	NoRebootOnCompletion          = $false
	SysvolPath                    = "C:\Windows\SYSVOL"
	Force                         = $true
}
Install-ADDSForest @params

That’s it.