42 lines
1.6 KiB
PowerShell
42 lines
1.6 KiB
PowerShell
#Requires -Modules 'DhcpServer'
|
|
Param(
|
|
[Parameter(Mandatory)]
|
|
[hashtable]$Parameter
|
|
)
|
|
|
|
# Only executed on secondary Domain Controller
|
|
If ($Parameter['deployment.type'] -eq 'secondary') {
|
|
# Wait for secondary DHCP server to be registered in DNS
|
|
$Timestamp, $TimeoutMinutes = (Get-Date), 5
|
|
Do {
|
|
If ($Timestamp.AddMinutes($TimeoutMinutes) -lt (Get-Date)) {
|
|
$WriteEventLogSplat = @{
|
|
LogName = 'Application'
|
|
Source = 'OVF-Properties'
|
|
EntryType = 'Warning'
|
|
EventID = 13
|
|
Message = "Timeout after $($TimeoutMinutes) minutes waiting for secondary Domain Controller to be registered in DNS."
|
|
}
|
|
Write-EventLog @WriteEventLogSplat
|
|
Break
|
|
}
|
|
|
|
Start-Sleep -Seconds 5
|
|
|
|
} Until ((Get-DhcpServerInDC).Count -gt 1)
|
|
|
|
$NewCimSessionSplat = @{
|
|
Credential = New-Object System.Management.Automation.PSCredential(
|
|
(Get-ADUser -Filter * | Where-Object {$_.SID -match '-500'}).SamAccountName,
|
|
(ConvertTo-SecureString $Parameter['addsconfig.administratorpw'] -AsPlainText -Force)
|
|
)
|
|
}
|
|
$AddDhcpServerv4FailoverSplat = @{
|
|
Name = 'Failover #42'
|
|
PartnerServer = (Get-DhcpServerInDC).DnsName | Where-Object {$_ -ne "$($Parameter['guestinfo.hostname']).$($Parameter['addsconfig.domainname'])"}
|
|
ServerRole = 'Active'
|
|
ScopeId = (Get-DhcpServerv4Scope).ScopeId.IPAddressToString
|
|
CimSession = New-CimSession @NewCimSessionSplat
|
|
}
|
|
Add-DhcpServerv4Failover @AddDhcpServerv4FailoverSplat
|
|
} |