Search code examples
powershellactive-directorypowershell-4.0powershell-remoting

Configuring a Active Directory Domain Services on Windows Server 2012


I am manually configuring a Active Directory Domain Services on Windows Server 2012 using below link every time a server is initiated. Any insight on this how we can automate each step using PS.

https://support.rackspace.com/how-to/installing-active-directory-on-windows-server-2012/

I have used below PS script to Install and configure AD. When I execute this its looking for parameter Domain Name. Do I need to Explicitly add this. If yes, How can I add with in the script.

import-module servermanager
Get-Windowsfeature 
Install-windowsfeature AD-domain-services 
Import-Module ADDSDeployment
Write-Host "Updating system" $env:COMPUTERNAME "....." -ForegroundColor Green 
Set-Service –Name remoteregistry –Computer $env:COMPUTERNAME -StartupType Automatic 
Get-Service remoteregistry -ComputerName $env:COMPUTERNAME | start-service 
Install-ADDSForest
 -CreateDnsDelegation:$false 
 -DatabasePath "C:\Windows\NTDS" 
 -DomainMode "Win2012R2" 
 -DomainName "corp.contoso.com"
 -DomainNetbiosName "THEGEEKSTUFF" 
 -ForestMode "Win2012R2" 
 -InstallDns:$true
 -LogPath "C:\Windows\NTDS" 
 -NoRebootOnCompletion:$false 
 -SysvolPath "C:\Windows\SYSVOL"
 -Force:$true

Domain name


Solution

  • updated:

    It is asking value for -DomainName parameter as it is Mandatory and the codes for Install-ADDSForest should be in a single line or you have to use backtick ` to split it into multiple lines. better to use in a line like below.

    Install-ADDSForest -CreateDnsDelegation:$false  -DatabasePath "C:\Windows\NTDS"  -DomainMode "Win2012R2"  -DomainName "corp.contoso.com" -DomainNetbiosName "THEGEEKSTUFF"  -ForestMode "Win2012R2"  -InstallDns:$true -LogPath "C:\Windows\NTDS"  -NoRebootOnCompletion:$false  -SysvolPath "C:\Windows\SYSVOL" -Force:$true
    

    Using Backtick:

    Install-ADDSForest`
    -CreateDnsDelegation:$false `
    -DatabasePath "C:\Windows\NTDS" `
    -DomainMode "Win2012R2" `
    -DomainName "corp.contoso.com"`
    -DomainNetbiosName "THEGEEKSTUFF" `
    -ForestMode "Win2012R2" `
    -InstallDns:$true`
    -LogPath "C:\Windows\NTDS" `
    -NoRebootOnCompletion:$false `
    -SysvolPath "C:\Windows\SYSVOL"`
    -Force:$true
    

    regards,

    kvprasoon