-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DSOS-2635: powershell ad updates for new DC (#600)
* fix typo * Rename Get-ModPlatformADCredential function * Add additional AD Credential functions * test * fix * fix * fix * fix * Fix * update
- Loading branch information
1 parent
eacf89a
commit 2edb9e6
Showing
10 changed files
with
256 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
powershell/Scripts/ModPlatformAD/Install-ModPlatformADDomainController.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<# | ||
.SYNOPSIS | ||
Install a Domain Controller from scratch | ||
.DESCRIPTION | ||
By default the script derives the hostname from the Name tag. Or specify NewHostname parameter. | ||
By default derives the AD configuration from EC2 tags (environment-name or domain-name), or specify DomainNameFQDN parameter. | ||
EC2 requires permissions to get tags and the aws cli. | ||
Exits with 3010 if reboot required and script requires re-running. For use in SSM docs | ||
.PARAMETER DomainNameFQDN | ||
Optionally specify the FQDN of the domain name to join | ||
.EXAMPLE | ||
Join-ModPlatformAD | ||
#> | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[string]$NewHostname = "tag:Name", | ||
[string]$DomainNameFQDN | ||
) | ||
|
||
Import-Module ModPlatformAD -Force | ||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
$ADConfig = Get-ModPlatformADConfig -DomainNameFQDN $DomainNameFQDN | ||
$ADSecret = Get-ModPlatformADSecret -ModPlatformADConfig $ADConfig | ||
$ADJoinCredential = Get-ModPlatformADJoinCredential -ModPlatformADConfig $ADConfig -ModPlatformADSecret $ADSecret | ||
$Renamed = Rename-ModPlatformADComputer -NewHostname $NewHostname -ModPlatformADCredential $ADJoinCredential | ||
if ($Renamed) { | ||
Write-Output "Renamed computer to ${Renamed}" | ||
Exit 3010 # triggers reboot if running from SSM Doc | ||
} | ||
if (Add-ModPlatformADComputer -ModPlatformADConfig $ADConfig -ModPlatformADCredential $ADJoinCredential) { | ||
Exit 3010 # triggers reboot if running from SSM Doc | ||
} | ||
|
||
$DFSReplicationStatus = Get-Service "DFS Replication" -ErrorAction SilentlyContinue | ||
if ($DFSReplicationStatus -eq $null) { | ||
$ADAdminCredential = Get-ModPlatformADAdminCredential -ModPlatformADConfig $ADConfig -ModPlatformADSecret $ADSecret | ||
$ADSafeModeAdministratorPassword = Get-ModPlatformADSafeModeAdministratorPassword -ModPlatformADConfig $ADConfig -ModPlatformADSecret $ADSecret | ||
Install-WindowsFeature -Name AD-Domain-Services -IncludeAllSubFeature -IncludeManagementTools | ||
Install-ADDSDomainController -DomainName $ADConfig.DomainNameFQDN -InstallDns:$true -Credential $ADAdminCredential -SafeModeAdministratorPassword $ADSafeModeAdministratorPassword -NoRebootOnCompletion -Force | ||
Exit 3010 # triggers reboot if running from SSM Doc | ||
} else { | ||
$Services='DNS','DFS Replication','Intersite Messaging','Kerberos Key Distribution Center','NetLogon',’Active Directory Domain Services’ | ||
ForEach ($Service in $Services) {Get-Service $Service | Select-Object Name, Status} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
powershell/Scripts/ModPlatformAD/Uninstall-ModPlatformADDomainController.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<# | ||
.SYNOPSIS | ||
Install a Domain Controller from scratch | ||
.DESCRIPTION | ||
By default the script derives the hostname from the Name tag. Or specify NewHostname parameter. | ||
By default derives the AD configuration from EC2 tags (environment-name or domain-name), or specify DomainNameFQDN parameter. | ||
EC2 requires permissions to get tags and the aws cli. | ||
Exits with 3010 if reboot required and script requires re-running. For use in SSM docs | ||
Example retrieval of local admin password: | ||
aws ssm get-parameter --name ec2-user_pem --with-decryption --query Parameter.Value --output text --profile hmpps-domain-services-test > tmp.key | ||
aws ec2 get-password-data --instance-id i-0aa02abedd9572e19 --profile core-shared-services-production-ad --priv-launch-key tmp.key | ||
rm tmp.key | ||
.PARAMETER DomainNameFQDN | ||
Optionally specify the FQDN of the domain name to join | ||
.EXAMPLE | ||
Join-ModPlatformAD | ||
#> | ||
|
||
[CmdletBinding()] | ||
param ( | ||
[string]$NewHostname = "tag:Name", | ||
[string]$DomainNameFQDN | ||
) | ||
|
||
Import-Module ModPlatformAD -Force | ||
|
||
$ErrorActionPreference = "Stop" | ||
|
||
$ADConfig = Get-ModPlatformADConfig -DomainNameFQDN $DomainNameFQDN | ||
$ADSecret = Get-ModPlatformADSecret -ModPlatformADConfig $ADConfig | ||
|
||
$DFSReplicationStatus = Get-Service "DFS Replication" -ErrorAction SilentlyContinue | ||
if ($DFSReplicationStatus -ne $null) { | ||
$ADAdminCredential = Get-ModPlatformADAdminCredential -ModPlatformADConfig $ADConfig -ModPlatformADSecret $ADSecret | ||
$ADSafeModeAdministratorPassword = Get-ModPlatformADSafeModeAdministratorPassword -ModPlatformADConfig $ADConfig -ModPlatformADSecret $ADSecret | ||
Uninstall-ADDSDomainController -Credential $ADAdminCredential -NoRebootOnCompletion -Force | ||
Exit 3010 # triggers reboot if running from SSM Doc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
$ErrorActionPreference = "Stop" | ||
|
||
. ../ModPlatformAD/Join-ModPlatformAD.ps1 | ||
. ../ModPlatformAD/Install-ModPlatformADDomainController.ps1 | ||
if ($LASTEXITCODE -ne 0) { | ||
Exit $LASTEXITCODE | ||
} | ||
|
||
Install-WindowsFeature AD-Domain-Services -IncludeAllSubFeature -IncludeManagementTools |