-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathRootConfiguration.ps1
58 lines (53 loc) · 2.65 KB
/
RootConfiguration.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
Write-Warning "---------->> Starting Configuration"
$BuildVersion = $Env:BuildVersion
Import-Module DscBuildHelpers -Scope Global
configuration "RootConfiguration"
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName SharedDscConfig -ModuleVersion 0.0.4
Import-DscResource -ModuleName Chocolatey -ModuleVersion 0.0.58
$module = Get-Module PSDesiredStateConfiguration
& $module {param($tag,$Env) $Script:PSTopConfigurationName = "MOF_$($Env)_$($tag)"} "$BuildVersion",$Environment
node $ConfigurationData.AllNodes.NodeName {
Write-Host "`r`n$('-'*75)`r`n$($Node.Name) : $($Node.NodeName) : $(& $module { $Script:PSTopConfigurationName })" -ForegroundColor Yellow
$env:PSModulePath = $goodPSModulePath
(Lookup 'Configurations').Foreach{
$configurationName = $_
$(Write-Debug "`tLooking up params for $configurationName")
$properties = $(lookup $configurationName -DefaultValue @{})
$dscError = [System.Collections.ArrayList]::new()
Get-DscSplattedResource -ResourceName $configurationName -ExecutionName $configurationName -Properties $properties
if($Error[0] -and $lastError -ne $Error[0]) {
$lastIndex = [Math]::Max( ($Error.LastIndexOf($lastError) -1), -1)
if($lastIndex -gt 0) {
$Error[0..$lastIndex].Foreach{
if($message = Get-DscErrorMessage -Exception $_.Exception) {
$null = $dscError.Add($message)
}
}
}
else {
if($message = Get-DscErrorMessage -Exception $Error[0].Exception) {
$null = $dscError.Add($message)
}
}
$lastError = $Error[0]
}
if($dscError.Count -gt 0) {
$warningMessage = " $($Node.Name) : $($Node.Role) ::> $_ "
$n = [System.Math]::Max(1, 120 - $warningMessage.Length)
Write-Host "$warningMessage$('.' * $n)FAILED" -ForeGroundColor Yellow
$dscError.Foreach{
Write-Host "`t$message" -ForeGroundColor Yellow
}
}
else {
$okMessage = " $($Node.Name) : $($Node.Role) ::> $_ "
$n = [System.Math]::Max(1, 120 - $okMessage.Length)
Write-Host "$okMessage$('.' * $n)OK" -ForeGroundColor Green
}
$lastCount = $Error.Count
}
}
}
RootConfiguration -ConfigurationData $ConfigurationData -OutputPath "$ProjectPath\BuildOutput\MOF\"