windowspowershellactive-directorydomaincontroller

PowerShell Script Install-ADDSDomainController Error


I'm having an issue with a PowerShell script I am writing to automate Domain Controller promotions in AD.

I get the following error when run:

Install-ADDSDomainController : Object reference not set to an instance of an object.
+ Install-ADDSDomainController -InstallDns -DomainName "$localdomain" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Install-ADDSDomainController], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.DirectoryServices.Deployment.PowerShell.Commands.InstallADDSDomainControllerCommand

This is the PowerShell script I wrote:

$Network = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE
$defaultgateway = ($Network.DefaultIPGateway -like "*.*.*.*")

$localsitedc = switch ($defaultgateway)
{
 "192.168.40.1"   {"DC0.east.contestco.local"}
 "192.168.41.1"   {"DC0.west.contestco.local"}
 "192.168.42.1"   {"DC0.north.contestco.local"}
 "192.168.43.1"   {"DC0.south.contestco.local"}
 "192.168.48.1"   {"DC0.mobile.contestco.local"}
}

$localdomain = "{1}" -f ($localsitedc.Split(".",2))

$seclocalpasswd = ConvertTo-SecureString "MySecretLocalPassword" -AsPlainText -Force
$secadmpasswd = ConvertTo-SecureString "MySecretADPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("CONTESTCO\Administrator", $secadmpasswd)

Install-ADDSDomainController -InstallDns -DomainName $localdomain -ReplicationSourceDC $localsitedc -SafeModeAdministratorPassword $seclocalpasswd -Credential $mycreds

Any help would be appreciated.

Thanks


Solution

  • I found that "-Force" was needed at the end of the Install-ADDSDomainController command. I forgot this command asked questions that the user needed to answer.