| | | |

Deploy Active Directory Domain Using PowerShell

Deploy Active Directory  Domain using PowerShell

Let’s start by Setting the PowerShell Execution Policy to Unrestricted

Set-ExecutionPolicy Unrestricted

Next we will rename the server and install Prereq features.

#rename the computer
$newname = “LAB-DC-01”
Rename-Computer -NewName $newname -force<
#install features
$featureLogPath = “c:\softlib\Shell\poshlog\featurelog.txt”
New-Item $featureLogPath -ItemType file -Force
$addsTools = “RSAT-AD-Tools”
Add-WindowsFeature $addsTools
Get-WindowsFeature | Where installed >>$featureLogPath
#restart the computer
Restart-Computer

After the script has run successfully the sever will restart , once restarted launch the #PowerShell Console again and run the second script. This will install all the needed features to install Active Directory

Add-ADFeatures.ps1
#Install AD DS, DNS and GPMC
$featureLogPath = “c:\softlib\Shell\poshlog\featurelog-AdFeature.txt”
start-job -Name addFeature -ScriptBlock {
Add-WindowsFeature -Name “ad-domain-services” -IncludeAllSubFeature -IncludeManagementTools
Add-WindowsFeature -Name “dns” -IncludeAllSubFeature -IncludeManagementTools
Add-WindowsFeature -Name “gpmc” -IncludeAllSubFeature -IncludeManagementTools }
Wait-Job -Name addFeature
Get-WindowsFeature | Where installed >>$featureLogPath

After the feature installation has completed we can move on to Configure new Forest and Domain.

#InstallNewForest.ps1
#Create New Forest, add Domain Controller 
$domainname = “ThatLazyAdmin.local” 
$netbiosName = “THATLAZYADMIN” 
Import-Module ADDSDeployment 
Install-ADDSForest -CreateDnsDelegation:$false ` 
-DatabasePath “C:\Windows\NTDS” ` 
-DomainMode “Win2012” ` 
-DomainName $domainname ` 
-DomainNetbiosName $netbiosName ` 
-ForestMode “Win2012” ` -InstallDns:$true ` 
-LogPath “C:\Windows\NTDS” ` 
-NoRebootOnCompletion:$false ` 
-SysvolPath “C:\Windows\SYSVOL” ` 
-Force:$true

When the Script is running you will be prompted for the “Recovery Mode Password” , Enter the Password and Confirm.

Once you have Entered and Confirmed the “Recovery Password” Press Enter.
You will received a Notification Message asking to confirm the next steps. The Server will be promoted to a domain controller and will be restarted . Enter “Y” to access and Press Enter.

Installation and Configuration in progress and will restart server once done.

Server starting up after restart

On the Logon Screen we can now see we have the Option to Login to the “Domain”

Domain Controller Configuration by running a quick #OneLiner

Get-WindowsFeatures *AD*

This #OneLiner lets us View all Features related to Active Directory.

Let’s view the Domain Functional and Forest Functional Level using the “GUI”

Open “Active Directory Domains and Trusts” , Right click on the Domain name and select “Properties”. On the General Page you can view “Domain and Forest Functional Levels”

To make sure our newly Domain Controller has been created correctly lets run another #PowerShell #OneLiner to Test the Domain and Forest.
Let’s start by testing the Domain Controller Installation

Test-ADDSDomainControllerInstallation

As then we can do the same for the “Forest Installation”

Test-ADDSForestInstallation

New Forest and Domain Controller Build Complete .

 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *