Creating Module

This commit is contained in:
Torsten Brendgen
2026-04-21 13:02:51 +02:00
parent 7c9b854aec
commit e10ab48bb4
14 changed files with 493 additions and 321 deletions

View File

@@ -0,0 +1,37 @@
function Copy-ConfigurationDataValue {
[CmdletBinding()]
Param(
[AllowNull()]
$Value
)
if($null -eq $Value){
return $null
}
if($Value -is [System.Collections.Specialized.OrderedDictionary]){
$Copy = [ordered]@{}
foreach($Entry in $Value.GetEnumerator()){
$Copy[$Entry.Name] = Copy-ConfigurationDataValue -Value $Entry.Value
}
return $Copy
}
if($Value -is [System.Collections.Hashtable]){
$Copy = @{}
foreach($Entry in $Value.GetEnumerator()){
$Copy[$Entry.Name] = Copy-ConfigurationDataValue -Value $Entry.Value
}
return $Copy
}
if($Value -is [System.Array]){
$Copy = @()
foreach($Item in $Value){
$Copy += ,(Copy-ConfigurationDataValue -Value $Item)
}
return ,$Copy
}
return $Value
}

View File

@@ -0,0 +1,16 @@
function Format-ConfigurationDataMergeKey {
[CmdletBinding()]
Param(
[AllowNull()]
$Item,
[Parameter(Mandatory=$true)]
[String[]]
$KeyNames
)
$Pairs = foreach($KeyName in $KeyNames){
"$KeyName=$(Get-ConfigurationDataItemValue -Item $Item -KeyName $KeyName)"
}
return ($Pairs -join ", ")
}

View File

@@ -0,0 +1,30 @@
function Get-ConfigurationDataArrayMergeKeyNames {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[String]
$ArrayName,
[AllowNull()]
$Item
)
$MergeKeyMap = @{
Instances = @("Name")
ConfigurationOptions = @("OptionName")
AdditionalScripts = @("ScriptName")
Templates = @("TemplateName")
AllNodes = @("NodeName")
Registry = @("Key","ValueName")
}
if($MergeKeyMap.ContainsKey($ArrayName)){
return $MergeKeyMap[$ArrayName]
}
$SearchItem = Get-ConfigurationDataArraySearchItem -Item $Item
if($null -ne $SearchItem){
return @($SearchItem.Name)
}
return @()
}

View File

@@ -0,0 +1,24 @@
function Get-ConfigurationDataArraySearchItem {
[CmdletBinding()]
Param(
[AllowNull()]
$Item
)
if($null -eq $Item){
return $null
}
if(-not (
($Item -is [System.Collections.Hashtable]) -or
($Item -is [System.Collections.Specialized.OrderedDictionary])
)){
return $null
}
return @(
$Item.GetEnumerator() |
Where-Object { ($_.Value -is [String]) -and ($_.Name -like "*Name") } |
Select-Object -First 1
)[0]
}

View File

@@ -0,0 +1,20 @@
function Get-ConfigurationDataItemValue {
[CmdletBinding()]
Param(
[AllowNull()]
$Item,
[Parameter(Mandatory=$true)]
[String]
$KeyName
)
if(-not (Test-ConfigurationDataItemContainsKey -Item $Item -KeyName $KeyName)){
return $null
}
if($Item -is [System.Collections.IDictionary]){
return $Item[$KeyName]
}
return $Item.$KeyName
}

View File

@@ -0,0 +1,20 @@
function Test-ConfigurationDataItemContainsKey {
[CmdletBinding()]
Param(
[AllowNull()]
$Item,
[Parameter(Mandatory=$true)]
[String]
$KeyName
)
if($null -eq $Item){
return $false
}
if($Item -is [System.Collections.IDictionary]){
return $Item.Contains($KeyName)
}
return $null -ne $Item.PSObject.Properties[$KeyName]
}

View File

@@ -0,0 +1,18 @@
function Test-ConfigurationDataItemHasKeys {
[CmdletBinding()]
Param(
[AllowNull()]
$Item,
[Parameter(Mandatory=$true)]
[String[]]
$KeyNames
)
foreach($KeyName in $KeyNames){
if(-not (Test-ConfigurationDataItemContainsKey -Item $Item -KeyName $KeyName)){
return $false
}
}
return $true
}

View File

@@ -0,0 +1,32 @@
function Test-ConfigurationDataItemKeyMatch {
[CmdletBinding()]
Param(
[AllowNull()]
$Left,
[AllowNull()]
$Right,
[Parameter(Mandatory=$true)]
[String[]]
$KeyNames
)
if($KeyNames.Count -eq 0){
return $false
}
foreach($KeyName in $KeyNames){
if(-not (Test-ConfigurationDataItemContainsKey -Item $Left -KeyName $KeyName)){
return $false
}
if(-not (Test-ConfigurationDataItemContainsKey -Item $Right -KeyName $KeyName)){
return $false
}
if((Get-ConfigurationDataItemValue -Item $Left -KeyName $KeyName) -ne (Get-ConfigurationDataItemValue -Item $Right -KeyName $KeyName)){
return $false
}
}
return $true
}

View File

@@ -0,0 +1,20 @@
function Test-ConfigurationDataItemWildcard {
[CmdletBinding()]
Param(
[AllowNull()]
$Item,
[Parameter(Mandatory=$true)]
[String[]]
$KeyNames
)
if($KeyNames.Count -ne 1){
return $false
}
if(-not (Test-ConfigurationDataItemContainsKey -Item $Item -KeyName $KeyNames[0])){
return $false
}
return (Get-ConfigurationDataItemValue -Item $Item -KeyName $KeyNames[0]) -eq "*"
}