Creating a new Active Directory forest with Powershell

From MyWiki
Jump to: navigation, search

Reference - http://www.out-null.eu/2014/06/13/howto-creating-new-active-directory-forest-with-powershell/


Install-WindowsFeature AD-Domain-Services –IncludeManagementTools
$DomainName = "smelly.socks"
$DomainNETBIOSName = "SMELLY"
$DomainMode = "Win2012R2"
$ForestMode = "Win2012R2"
$DBPath = "C:\NTDS"
$LogPath = "C:\NTDS"
$SysvolPath = "C:\Sysvol"
 
Write-host "Installing AD Domain Services feature" -foregroundcolor yellow
$command = Install-WindowsFeature AD-Domain-Services –IncludeManagementTools
if ($command.Success -eq $true)
{
Write-host "AD Domain Services feature was installed successfully" -foregroundcolor green
Write-host "Installing New AD forest : $DomainName" -foregroundcolor yellow
$SafeModePass = Read-Host -AsSecureString -Promtp "Please enter safe mode administrator password"
$command = Install-ADDSForest -DomainName $DomainName -DomainNetbiosName $DomainNetbiosName -SafeModeAdministratorPassword $SafeModePass -DatabasePath $DBPath -LogPath $LogPath -SysvolPath $sysvolPath -DomainMode $DomainMode -ForestMode $ForestMode -InstallDns -NoRebootOnCompletion
if ($command.Success -eq $true)
{
Write-host "Forest : $DomainName created successfully, server will be rebooted in 30 seconds" -foregroundcolor green
Reboot-Computer -force -wait 30
}
else
{
Write-host "Forest : $DomainName creation has failed" -foregroundcolor red
}
}
else
{
Write-host "Installation of AD Domain Services feature has failed" -foregroundcolor red
}