Wednesday, 7 October 2015

Install and Configure Active Directory and DNS with PowerShell


I have created this script to install and Configure Active Directory services & DNS

Please save below script as "Install_Configure_AD_DNS.Ps1" file and execute in Powershell with Administrator rights on Server.

References : 
https://technet.microsoft.com/en-us/library/hh974720(v=wps.630).aspx



#----------------------------------------------------------------------------#
#Script Title : Install and Configure Active Directory and DNS
#Script Author : KRR
#----------------------------------------------------------------------------#
Import-Module ServerManager
Write-Host "Installing the windows feature: Active Directory Domain Service" -ForegroundColor "Green"
Install-windowsfeature AD-domain-services  –IncludeManagementTools
Write-Host "Active Directory Domain Service Installed successfully!!!" -ForegroundColor "Green"
Write-Host "Importing Active Directory Module..........." -ForegroundColor "Yellow"
Import-Module ADDSDeployment
Write-Host "Importing Active Directory Module Done" -ForegroundColor "Green"
#----------------------------------------------------------------------------------------#
Write-Host "Please enter the below details to configure AD and DNS" -ForegroundColor "Blue"
#-----------------------------------------------------------------------------------------#
$DomainandForestModes = @("-- Windows Server 2003: 2 or Win2003","-- Windows Server 2008: 3 or Win2008","-- Windows Server 2008 R2: 4 or Win2008R2","-- Windows Server 2012: 5 or Win2012","-- Windows Server 2012 R2: 6 or Win2012R")
#------------------------------------------------------------------------------------------#
Write-Host "Below are the domain and Forest function levels..." -ForegroundColor "Yellow"
$DomainandForestModes
$domainMode = Read-Host "Please enter Domain Functional Mode number or Value"
$ForestMode = Read-Host "Please enter Forest Functional Level"
$InstallDNS = Read-Host "Please enter '$true' if you want install DNS"
$DomainName = Read-Host "Please enter Domain Name , Example : corp.com"
$DomainNetbiosName = Read-Host "Please enter Domain NetBios Name , Example : corp"
#------------------------------------------------------------------------------------------#
Write-Host " Active Directory  and DNS configuration is in-progress" -ForegroundColor "Green"
Install-ADDSForest  -CreateDnsDelegation:$false -DatabasePath "C:\Windows\NTDS" -DomainMode $domainMode -DomainName $DomainName -DomainNetbiosName $DomainNetbiosName -ForestMode $ForestMode -InstallDns:$InstallDNS -LogPath "C:\Windows\NTDS" -NoRebootOnCompletion:$false -SysvolPath "C:\Windows\SYSVOL" -Force:$true
#-----------------------------------------------------------------------------------------------#
Write-Host "Active Directory and DNS configuration Completed!" -ForegroundColor "Green"

#--------------------------------End-----------------------------------------------------------#

Please feel to add comments and suggestions

Thanks
KRR

No comments:

Post a Comment