-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParameters.psm1
53 lines (47 loc) · 1.52 KB
/
Parameters.psm1
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
Set-StrictMode -Version 2.0
Function Get-ParameterNamesFromCommand ([Parameter(Mandatory)] [string] $CommandName)
{
$parameters = Invoke-Expression "(gcm $($CommandName)).Parameters"
foreach ($h in $parameters.GetEnumerator()) {
$h.Key
}
}
Function Get-ParameterNamesFromSitecoreConfiguration ([Parameter(Mandatory)] [string] $Path)
{
$json = Get-Content -Path $Path -Raw | ConvertFrom-Json
$json.Parameters | Get-Member -MemberType NoteProperty | ForEach-Object {
$_.Name
}
}
Function Get-EffectiveParametersForCommand
(
[Parameter(Mandatory)] [string] $CommandName,
[Parameter(Mandatory)] [Hashtable] $SourceParameters
)
{
$ParameterNames = Get-ParameterNamesFromCommand $CommandName
Return Get-EffectiveParameters $ParameterNames $SourceParameters
}
Function Invoke-CommandWithEffectiveParameters
(
[Parameter(Mandatory)] [string] $CommandName,
[Parameter(Mandatory)] [Hashtable] $SourceParameters
)
{
$Parameters = Get-EffectiveParametersForCommand $CommandName $SourceParameters
Invoke-Expression "$CommandName @Parameters"
}
Function Get-EffectiveParameters
(
[Parameter(Mandatory)] $ParameterNames,
[Parameter(Mandatory)] [Hashtable] $SourceParameters
)
{
$params = @{}
foreach ($ParameterName in $ParameterNames.GetEnumerator()) {
If ($SourceParameters.ContainsKey($ParameterName)) {
$params[$ParameterName] = $SourceParameters[$ParameterName]
}
}
Return $params
}