Skip to content

Add install active directory install command #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion samples/action_scripts/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,15 @@
"/f"
]
]
}
},

"INSTALL_ACTIVE_DIRECTORY_DOMAIN_SERVICES": {
"TYPE": "SCRIPT",
"FILENAME": "action_scripts/install_active_directory_forest.ps1",
"INTERPRETER": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"UPLOAD_DIR": "C:\\Windows\\Temp",
"SUCCESS_TYPE": "PROCESS",
"SUCCESS_METRIC": "Microsoft.ActiveDirectory.WebServices.exe",
"WAIT_SECONDS": 1200
}
}
78 changes: 78 additions & 0 deletions samples/action_scripts/install_active_directory_forest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Enforce best practices in Powershell
Set-StrictMode -Version 1.0
# Exit if a cmdlet fails
$ErrorActionPreference = "Stop"

# Configuration
$domain = "demo.local"
$plaintextPassword = "vagrant"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this get the VM password from the launch config for manageServices.py? I don't mind a hardcode value however I that is not super friendly to the those that may want to have at least some security in the testing env.


##################################################################################
# Password policy configuration
##################################################################################

Write-Host -fore green $ 'Running password policy logic'

# Ensure passwords never expire
net accounts /maxpwage:unlimited

# Disable automatic machine account password changes
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetLogon\Parameters' -Name DisablePasswordChange -Value 1

# Allow weak passwords
secedit /export /cfg c:\secpol.cfg
(Get-Content C:\secpol.cfg).replace("PasswordComplexity = 1", "PasswordComplexity = 0") | Out-File C:\secpol.cfg
secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY
rm -force c:\secpol.cfg -confirm:$false

#####################################################################################
# Forest installation
#####################################################################################

Write-Host -fore green $ 'Running forest installation'

$safeModeAdministratorPassword = ConvertTo-SecureString $plaintextPassword -AsPlainText -Force

# Set local Administrator account password to stop the error:
# "The new domain cannot be created DC01: because the local Administrator account password does not meet requirements."
Write-Host -fore green $ 'Setting local administrator password'
Set-LocalUser `
-Name Administrator `
-AccountNeverExpires `
-Password $safeModeAdministratorPassword `
-PasswordNeverExpires:$true `
-UserMayChangePassword:$true

Install-WindowsFeature AD-Domain-Services,RSAT-AD-AdminCenter,RSAT-ADDS-Tools -IncludeManagementTools -Verbose

#
# Install the Active Directory Domain Services (AD DS) environment
#

# Win32_operatingSystem ProductType
# Work Station (1)
# Domain Controller (2)
# Server (3)
# https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem
$isDomainController = (Get-WmiObject -Class Win32_operatingSystem).ProductType -Eq 2
Write-Host -fore green $ 'IsDomainController='$isDomainController
if (!$isDomainController) {
Write-Host -fore green $ 'Installing ADDS'
$netbios = $domain.split('.')[0].ToUpperInvariant()
Install-ADDSForest `
-CreateDnsDelegation:$false `
-DatabasePath "C:\Windows\NTDS" `
-DomainMode "Win2012R2" `
-DomainName $domain `
-DomainNetbiosName $netbios `
-ForestMode "Win2012R2" `
-InstallDns:$true `
-LogPath "C:\Windows\NTDS" `
-NoRebootOnCompletion:$false `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true `
-SafeModeAdministratorPassword $safeModeAdministratorPassword `
-Verbose
}

Write-Host -fore green $ 'Finished forest installation'