Deploy Active Directory Domain using PowerShell
Let’s start by Setting the PowerShell Execution Policy to Unrestricted
1 |
Set-ExecutionPolicy Unrestricted |
Next we will rename the server and install Prereq features.
1 2 3 4 5 6 7 8 9 10 11 |
<strong>#rename the computer</strong> $newname = “LAB-DC-01” Rename-Computer -NewName $newname -force< <strong>#install features</strong> $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 <strong>#restart the computer</strong> 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
1 2 3 4 5 6 7 8 9 |
<strong>Add-ADFeatures.ps1</strong> <strong>#Install AD DS, DNS and GPMC</strong> $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.
1 |
<strong>#InstallNewForest.ps1</strong> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<strong>#Create New Forest, add Domain Controller</strong> $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
1 |
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
1 |
Test-ADDSDomainControllerInstallation |
As then we can do the same for the “Forest Installation”
1 |
Test-ADDSForestInstallation |
New Forest and Domain Controller Build Complete .
Be First to Comment