-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-LabDC.ps1
53 lines (44 loc) · 2.01 KB
/
Add-LabDC.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$LabName,
[Parameter(Mandatory = $true)]
[string]$VMHostname,
[Parameter(Mandatory = $true)]
[string]$Username,
[Parameter(Mandatory = $true)]
[string]$Password,
[Parameter(Mandatory = $true)]
[string]$DomainUsername,
[Parameter(Mandatory = $true)]
[string]$DomainPassword,
[Parameter(Mandatory = $true)]
[string]$DomainName,
[Parameter(Mandatory = $true)]
[string]$SafeModeAdministratorPassword
)
$VMName = "$LabName-$VMHostname"
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Username, $SecurePassword)
$Session = New-PSSession -VMName $VMName -Credential $Credential
Invoke-Command -Session $Session -ScriptBlock {Install-WindowsFeature -Name AD-Domain-Services, DNS -IncludeManagementTools}
$SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $SafeModeAdministratorPassword -AsPlainText -Force
$SecureDomainPassword = ConvertTo-SecureString -String $DomainPassword -AsPlainText -Force
$DomainCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($DomainUsername, $SecureDomainPassword)
$ScriptBlock = {
Import-Module -Name ADDSDeployment
$Parameters = @{
DomainName = $using:DomainName
Credential = $using:DomainCredential
DatabasePath = 'C:\Windows\NTDS'
LogPath = 'C:\Windows\NTDS'
SysvolPath = 'C:\Windows\SYSVOL'
SafeModeAdministratorPassword = $using:SecureSafeModeAdministratorPassword
InstallDns = $true
NoRebootOnCompletion = $false
Confirm = $false
Verbose = $true
}
Install-ADDSDomainController @Parameters
}
Invoke-Command -Session $Session -ScriptBlock $ScriptBlock