-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-LabDomain.ps1
52 lines (43 loc) · 1.88 KB
/
New-LabDomain.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
[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]$DomainName,
[Parameter(Mandatory = $true)]
[string]$DomainNetBIOSName,
[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
$ScriptBlock = {
Import-Module -Name ADDSDeployment
$Parameters = @{
DomainName = $using:DomainName
DomainNetbiosName = $using:DomainNetBIOSName
ForestMode = 'WinThreshold'
DomainMode = 'WinThreshold'
DatabasePath = 'C:\Windows\NTDS'
LogPath = 'C:\Windows\NTDS'
SysvolPath = 'C:\Windows\SYSVOL'
SafeModeAdministratorPassword = $using:SecureSafeModeAdministratorPassword
InstallDns = $true
CreateDnsDelegation = $false
NoRebootOnCompletion = $false
Confirm = $false
Verbose = $true
}
Install-ADDSForest @Parameters
}
Invoke-Command -Session $Session -ScriptBlock $ScriptBlock