forked from dsccommunity/DscWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RootConfiguration.ps1
57 lines (51 loc) · 2.53 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
$Error.Clear()
$goodPSModulePath = $Env:PSModulePath
configuration "RootConfiguration"
{
Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName Common -ModuleVersion 0.0.1
$module = Get-Module PSDesiredStateConfiguration
$null = & $module {param($tag,$Env) Set-PSTopConfigurationName "MOF_$($Env)_$($tag)"} "$Env:BuildVersion" $Env:Environment
node $ConfigurationData.AllNodes.NodeName {
Write-Host "`r`n$('-'*75)`r`n$($Node.Name) : $($Node.NodeName) : $(&$module { Get-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 $_) {
$null = $DscError.Add($Message)
}
}
}
else {
if($Message = Get-DscErrorMessage -Exception $Error[0]) {
$null = $DscError.add($Message)
}
}
$lastError = $Error[0]
}
if($DscError.count -gt 0) {
$FailMessage = " $($Node.Name) : $($Node.Role) ::> $_ "
Write-Host -ForeGroundColor Red ($FailMessage + '.' * (55 - $FailMessage.Length) + 'FAILED')
$DscError.Foreach{
Write-Host -ForeGroundColor Yellow "`t$Message"
}
}
else {
$OkMessage = " $($Node.Name) : $($Node.Role) ::> $_ "
Write-Host -ForeGroundColor Green ($OkMessage + '.' * (55 -$OkMessage.Length) + 'OK')
}
$LastCount = $Error.Count
)
}
}
}
RootConfiguration -ConfigurationData $ConfigurationData -Out "$BuildRoot\BuildOutput\MOF\"