- Updated Export-ConfigurationData to use resolved configuration data directly and added error handling for missing data. - Enhanced Load-Templates to streamline category loading and improve error handling for missing template directories. - Removed Merge-ConfigurationData function as it is no longer needed. - Refactored Merge-Templates to improve merging logic and handle default files more effectively. - Introduced Get-TemplatePreviewData function to handle template preview data retrieval and merging. - Added Import-OrderedPowerShellDataFile function to support ordered hashtable imports. - Updated Update-ParametersPanel to handle parameter and variable tab updates more efficiently. - Improved Update-TreeView to handle cases where resources are not found. - Added new parameters to Environment.Default.psd1 for Active Directory configuration. - Created new template BGW-LAN.psd1 for domain configuration.
82 lines
2.9 KiB
PowerShell
82 lines
2.9 KiB
PowerShell
function Merge-Templates {
|
|
$Errors = @()
|
|
$MergedConfigurationData = $null
|
|
$MergeFiles = @()
|
|
$AddedDefaultFiles = @{}
|
|
|
|
for ($i = 0; $i -lt $selectionList.Items.Count; $i++) {
|
|
$item = $selectionList.Items[$i]
|
|
$file = $item.FullName
|
|
|
|
if (-not (Test-Path $file)) {
|
|
$Errors += "Datei nicht gefunden: $file"
|
|
continue
|
|
}
|
|
|
|
$directory = Split-Path -Path $file -Parent
|
|
$defaultFiles = @(Get-ChildItem -Path $directory -Filter "*.psd1" -File -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.BaseName -eq "Default" -or $_.BaseName -like "*.Default" } |
|
|
Sort-Object Name)
|
|
|
|
foreach($defaultFile in $defaultFiles){
|
|
if(-not $AddedDefaultFiles.ContainsKey($defaultFile.FullName)){
|
|
$MergeFiles += $defaultFile.FullName
|
|
$AddedDefaultFiles[$defaultFile.FullName] = $true
|
|
}
|
|
}
|
|
|
|
$MergeFiles += $file
|
|
}
|
|
|
|
foreach($file in $MergeFiles){
|
|
try {
|
|
try {
|
|
$TemplateData = Import-PowerShellDataFile -Path $file -ErrorAction Stop
|
|
}
|
|
catch {
|
|
$Errors += "Datei konnte nicht importiert werden: $file"
|
|
continue
|
|
}
|
|
|
|
if($null -eq $MergedConfigurationData){
|
|
$MergedConfigurationData = $TemplateData
|
|
}else{
|
|
$MergedConfigurationData = Merge-DSCConfigurationData -Template $MergedConfigurationData -Deployment $TemplateData
|
|
}
|
|
}
|
|
catch {
|
|
$Errors += "Fehler beim Verarbeiten $($file): $($_.Exception.Message)"
|
|
}
|
|
}
|
|
|
|
if ($null -ne $MergedConfigurationData) {
|
|
try {
|
|
$script:MergedConfigurationData = $MergedConfigurationData
|
|
$script:ResolvedConfigurationData = Resolve-DSCConfigurationData -ConfigurationData $MergedConfigurationData
|
|
}
|
|
catch {
|
|
$Errors += "Fehler beim Auflösen der ConfigurationData: $($_.Exception.Message)"
|
|
$script:ResolvedConfigurationData = $null
|
|
}
|
|
|
|
if($null -ne $script:ResolvedConfigurationData){
|
|
Update-TreeView -ConfigurationData $script:ResolvedConfigurationData
|
|
}else{
|
|
Update-TreeView -ConfigurationData $MergedConfigurationData
|
|
}
|
|
|
|
$statusBar.SetText("Status", "Merge erfolgreich: $($selectionList.Items.Count) Queue-Dateien, $($MergeFiles.Count) inklusive Defaults")
|
|
}
|
|
else {
|
|
Update-TreeView -ConfigurationData $MergedConfigurationData
|
|
$statusLabel.Text = "Merge ergab kein Ergebnis"
|
|
}
|
|
|
|
if ($Errors.Count -gt 0) {
|
|
[System.Windows.Forms.MessageBox]::Show(($Errors -join "`r`n"), "Merge Warnungen", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning)
|
|
return
|
|
}
|
|
|
|
return $script:ResolvedConfigurationData
|
|
}
|