Creating Module
This commit is contained in:
37
Private/Copy-ConfigurationDataValue.ps1
Normal file
37
Private/Copy-ConfigurationDataValue.ps1
Normal 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
|
||||
}
|
||||
16
Private/Format-ConfigurationDataMergeKey.ps1
Normal file
16
Private/Format-ConfigurationDataMergeKey.ps1
Normal 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 ", ")
|
||||
}
|
||||
30
Private/Get-ConfigurationDataArrayMergeKeyNames.ps1
Normal file
30
Private/Get-ConfigurationDataArrayMergeKeyNames.ps1
Normal 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 @()
|
||||
}
|
||||
24
Private/Get-ConfigurationDataArraySearchItem.ps1
Normal file
24
Private/Get-ConfigurationDataArraySearchItem.ps1
Normal 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]
|
||||
}
|
||||
20
Private/Get-ConfigurationDataItemValue.ps1
Normal file
20
Private/Get-ConfigurationDataItemValue.ps1
Normal 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
|
||||
}
|
||||
20
Private/Test-ConfigurationDataItemContainsKey.ps1
Normal file
20
Private/Test-ConfigurationDataItemContainsKey.ps1
Normal 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]
|
||||
}
|
||||
18
Private/Test-ConfigurationDataItemHasKeys.ps1
Normal file
18
Private/Test-ConfigurationDataItemHasKeys.ps1
Normal 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
|
||||
}
|
||||
32
Private/Test-ConfigurationDataItemKeyMatch.ps1
Normal file
32
Private/Test-ConfigurationDataItemKeyMatch.ps1
Normal 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
|
||||
}
|
||||
20
Private/Test-ConfigurationDataItemWildcard.ps1
Normal file
20
Private/Test-ConfigurationDataItemWildcard.ps1
Normal 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 "*"
|
||||
}
|
||||
Reference in New Issue
Block a user