-
Notifications
You must be signed in to change notification settings - Fork 1
/
domain.ps1
96 lines (91 loc) · 2.76 KB
/
domain.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$configName = "SPDomain"
Write-Host "$(Get-Date) Defining DSC"
try
{
Configuration $configName
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$ShortDomainAdminCredential,
[Parameter(Mandatory=$true)]
[ValidateNotNullorEmpty()]
[PSCredential]
$DomainSafeModeAdministratorPasswordCredential
)
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName ActiveDirectoryDsc -ModuleVersion 5.0.0
$domainName = "contoso.local";
Node $AllNodes.NodeName
{
ADDomain ADDomain
{
DomainName = $domainName
SafemodeAdministratorPassword = $domainSafeModeAdministratorPasswordCredential
Credential = $shortDomainAdminCredential
}
}
}
}
catch
{
Write-Host "$(Get-Date) Exception in defining DCS:"
$_.Exception.Message
Exit 1;
}
$configurationData = @{ AllNodes = @(
@{ NodeName = $env:COMPUTERNAME; PSDscAllowPlainTextPassword = $True; PsDscAllowDomainUser = $True }
) }
$securedPassword = ConvertTo-SecureString "Fractalsol365" -AsPlainText -Force
$ShortDomainAdminCredential = New-Object System.Management.Automation.PSCredential( "vagrant", $securedPassword )
$securedPassword = ConvertTo-SecureString "sUp3rcomp1eX" -AsPlainText -Force
$DomainSafeModeAdministratorPasswordCredential = New-Object System.Management.Automation.PSCredential( "fakeaccount", $securedPassword )
Write-Host "$(Get-Date) Compiling DSC"
try
{
&$configName `
-ConfigurationData $configurationData `
-ShortDomainAdminCredential $ShortDomainAdminCredential `
-DomainSafeModeAdministratorPasswordCredential $DomainSafeModeAdministratorPasswordCredential;
}
catch
{
Write-Host "$(Get-Date) Exception in compiling DCS:";
$_.Exception.Message
Exit 1;
}
Write-Host "$(Get-Date) Starting DSC"
try
{
Start-DscConfiguration $configName -Verbose -Wait -Force;
}
catch
{
Write-Host "$(Get-Date) Exception in starting DCS:"
$_.Exception.Message
Exit 1;
}
if ( $env:VMDEVOPSSTARTER_NODSCTEST -ne "TRUE" )
{
Write-Host "$(Get-Date) Testing DSC"
try {
$result = Test-DscConfiguration $configName -Verbose;
$inDesiredState = $result.InDesiredState;
$failed = $false;
$inDesiredState | % {
if ( !$_ ) {
Write-Host "$(Get-Date) Test failed"
Exit 1;
}
}
}
catch {
Write-Host "$(Get-Date) Exception in testing DCS:"
$_.Exception.Message
Exit 1;
}
} else {
Write-Host "$(Get-Date) Skipping tests"
}
Exit 0;