1
1
# Requires -Version 4
2
2
Function Merge-DscConfigData {
3
3
[CmdletBinding ()]
4
-
4
+
5
5
Param (
6
6
[Parameter (Mandatory = $True , Position = 0 )]
7
7
[string ]$BaseConfigFilePath ,
@@ -36,26 +36,26 @@ Function Merge-DscConfigData {
36
36
37
37
# Proceeding with the merge only if $OverrideConfig is not null and has been evaluated as a hashtable
38
38
If ( $OverrideConfig -and ($OverrideConfig -is [hashtable ]) ) {
39
-
39
+
40
40
# Casting the AllNodes array to a list in order to add elements to it
41
41
$BaseNodes = $BaseConfig.AllNodes -as [System.Collections.ArrayList ]
42
-
42
+
43
43
Foreach ( $Node in $OverrideConfig.AllNodes ) {
44
-
44
+
45
45
$NodeInBaseConfig = $BaseNodes | Where-Object { $_.NodeName -eq $Node.NodeName }
46
46
47
47
If ( $NodeInBaseConfig ) {
48
-
48
+
49
49
Write-Verbose " The node $ ( $Node.NodeName ) is already present in the base config."
50
50
51
51
# Removing the NodeName entry from the current Node to keep only the actual settings
52
52
$Node.Remove (' NodeName' )
53
53
54
54
Foreach ($OverrideSettingKey in $Node.keys ) {
55
-
55
+
56
56
# Checking if the setting already exists in the Base config
57
57
$KeyExistsInBaseNode = $NodeInBaseConfig.ContainsKey ($OverrideSettingKey )
58
-
58
+
59
59
If ( $KeyExistsInBaseNode ) {
60
60
Write-Verbose " $ ( $NodeInBaseConfig.NodeName ) .$OverrideSettingKey , in node $ ( $NodeInBaseConfig.NodeName ) is present in the base config, overriding its value."
61
61
$NodeInBaseConfig .$ ($OverrideSettingKey ) = $Node .$ ($OverrideSettingKey )
@@ -67,7 +67,7 @@ Function Merge-DscConfigData {
67
67
}
68
68
}
69
69
Else { # If the node is not already present in the base base config
70
-
70
+
71
71
Write-Verbose " The node $ ( $Node.NodeName ) is absent in the base config, adding it."
72
72
$Null = $BaseNodes.Add ($Node )
73
73
}
@@ -78,21 +78,21 @@ Function Merge-DscConfigData {
78
78
if ($OverrideConfig.NonNodeData -ne $null ) {
79
79
80
80
if ($BaseConfig.NonNodeData -eq $null ) {
81
-
81
+
82
82
# Use NonNodeData, in its entirety, from the Override configuration if NonNodeData does not exist in the Base configuration
83
83
$BaseConfig.NonNodeData = $OverrideConfig.NonNodeData
84
84
85
85
} else {
86
86
87
87
foreach ($NonNodeSetting in $OverrideConfig.NonNodeData.GetEnumerator ()) {
88
-
88
+
89
89
# Checking if the setting already exists in the Base config
90
90
if ($BaseConfig.NonNodeData.ContainsKey ($NonNodeSetting.name ))
91
91
{
92
92
Write-Verbose - Message " The setting $ ( $NonNodeSetting.name ) is present in the base config, overring its value."
93
93
$BaseConfig.NonNodeData.Set_Item ($NonNodeSetting.Name , $NonNodeSetting.value )
94
94
}
95
- else
95
+ else
96
96
{
97
97
Write-Verbose - Message " The setting $ ( $NonNodeSetting.name ) is absent in the base config, ading it."
98
98
$BaseConfig.NonNodeData.Add ($NonNodeSetting.Name , $NonNodeSetting.value )
0 commit comments