Permalink
Browse files

Added dynamic param for config updates

Added dynamic parameters to allow specifying settings only for this process.
  • Loading branch information...
Friedrich Weinmann
Friedrich Weinmann committed Jan 11, 2018
1 parent e7ef47e commit eed925c7b67cf6e9ce3285ad044ae2687044a338
Showing with 30 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +28 −0 functions/Invoke-DbcCheck.ps1
@@ -2,8 +2,9 @@
dbachecks.psprojs
config.json

# ignore files for VS and VS Code
# ignore files for VS and VS Code and PowerShell Studio
.vs/*
.vscode/*
*.pssproj
*.sln
*.TempPoint.*
@@ -202,6 +202,34 @@
[Pester.OutputTypes]$Show = 'All'
)

dynamicparam {
$config = Get-PSFConfig -Module dbachecks

$RuntimeParamDic = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary

foreach ($setting in $config) {
$ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
$ParamAttrib.ParameterSetName = '__AllParameterSets'
$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$AttribColl.Add($ParamAttrib)

$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter("Dbc$($setting.Name.Replace('.',''))", [object], $AttribColl)

$RuntimeParamDic.Add("Dbc$($setting.Name.Replace('.', ''))", $RuntimeParam)
}
return $RuntimeParamDic
}

begin {
$config = Get-PSFConfig -Module dbachecks

foreach ($key in $PSBoundParameters.Keys | Where-Object { $_ -like "Dbc*" }) {
if ($item = $config | Where-Object { "Dbc$($_.Name.Replace('.', ''))" -eq $key }) {
Set-PSFConfig -Module dbachecks -Name $item.Name -Value $PSBoundParameters.$key
}
}
}

process {

if (-not $Script -and -not $TestName -and -not $Check -and -not $ExcludeCheck -and -not $AllChecks) {

0 comments on commit eed925c

Please sign in to comment.