Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion plugins/modules/domain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ catch [System.DirectoryServices.ActiveDirectory.ActiveDirectoryOperationExceptio
$forest = $null
}

if (-not $forest) {
try {
# ProductType 2 means the host is a domain controller, 1 means it's a workstation and 3 means it's a server that is a server
$host_is_dc = (Get-CimInstance -ClassName Win32_OperatingSystem -Property ProductType).ProductType -eq 2
}
catch {
$module.FailJson("Failed to determine if the host is already a domain controller: $($_.Exception.Message)")
}

# Only installing the domain if the forest does not exist or the host is not a domain controller
# This is to avoid an issue where the domain may already exist in another domain controller but the host itself is not a DC
# By trying to run Install-ADDSForest in that scenario it will fail with the correct error message
if (-not $forest -or -not $host_is_dc) {
$installParams = @{
DomainName = $dns_domain_name
SafeModeAdministratorPassword = (ConvertTo-SecureString $safe_mode_password -AsPlainText -Force)
Expand Down