This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
forked from adbertram/TestDomainCreator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNewTestEnvironment.ps1
67 lines (59 loc) · 2.77 KB
/
NewTestEnvironment.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
configuration NewTestEnvironment {
param(
[Parameter(Mandatory)]
[PSCredential] $defaultAdUserCred,
[Parameter(Mandatory)]
[PSCredential] $domainSafeModeCred
)
Import-DscResource -ModuleName xActiveDirectory
Node $AllNodes.where( { $_.Purpose -eq 'Domain Controller' }).NodeName {
@($ConfigurationData.NonNodeData.ADGroups).foreach( {
xADGroup $_ {
Ensure = 'Present'
GroupName = $_
DependsOn = '[xADDomain]ADDomain'
}
})
@($ConfigurationData.NonNodeData.OrganizationalUnits).foreach( {
xADOrganizationalUnit $_ {
Ensure = 'Present'
Name = ($_ -replace '-')
Path = ('DC={0},DC={1},DC={2}' -f
($ConfigurationData.NonNodeData.DomainName -split '\.')[0],
($ConfigurationData.NonNodeData.DomainName -split '\.')[1],
($ConfigurationData.NonNodeData.DomainName -split '\.')[2])
DependsOn = '[xADDomain]ADDomain'
}
})
@($ConfigurationData.NonNodeData.ADUsers).foreach( {
xADUser "$($_.FirstName) $($_.LastName)" {
Ensure = 'Present'
DomainName = $ConfigurationData.NonNodeData.DomainName
GivenName = $_.FirstName
SurName = $_.LastName
UserName = ('{0}{1}' -f $_.FirstName.SubString(0, 1), $_.LastName)
Department = $_.Department
Path = ('OU={0},DC={1},DC={2},DC={3}' -f $_.Department,
($ConfigurationData.NonNodeData.DomainName -split '\.')[0],
($ConfigurationData.NonNodeData.DomainName -split '\.')[1],
($ConfigurationData.NonNodeData.DomainName -split '\.')[2])
JobTitle = $_.Title
Password = $defaultAdUserCred
DependsOn = '[xADDomain]ADDomain'
}
})
($Node.WindowsFeatures).foreach( {
WindowsFeature $_ {
Ensure = 'Present'
Name = $_
}
})
xADDomain ADDomain {
DomainName = $ConfigurationData.NonNodeData.DomainName
DomainAdministratorCredential = $domainSafeModeCred
SafemodeAdministratorPassword = $domainSafeModeCred
DependsOn = '[WindowsFeature]AD-Domain-Services'
}
}
}
NewTestEnvironment -OutputPath $env:USERPROFILE\DSC -ConfigurationData .\ConfigurationData.psd1