-
Notifications
You must be signed in to change notification settings - Fork 8
/
NewTestEnvironment.ps1
70 lines (62 loc) · 2.7 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
68
69
70
configuration NewTestEnvironment
{
Import-DscResource -ModuleName xActiveDirectory
## Authenticate to Azure
Login-AzureRmAccount
## This will be invoked by Azure Automation so grab the Azure Automation DSC credential asset and use it.
$credParams = @{
ResourceGroupName = 'Group'
AutomationAccountName = 'adamautomation'
}
$defaultAdUserCred = Get-AutomationPSCredential -Name 'Default AD User Password'
$domainSafeModeCred = Get-AutomationPSCredential -Name 'Domain safe mode'
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}' -f ($ConfigurationData.NonNodeData.DomainName -split '\.')[0], ($ConfigurationData.NonNodeData.DomainName -split '\.')[1])
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}" -f $_.Department, ($ConfigurationData.NonNodeData.DomainName -split '\.')[0], ($ConfigurationData.NonNodeData.DomainName -split '\.')[1])
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'
}
}
}