diff --git a/PSDeploy/Private/Get-ParameterSetInUse.ps1 b/PSDeploy/Private/Get-ParameterSetInUse.ps1 new file mode 100644 index 0000000..1851316 --- /dev/null +++ b/PSDeploy/Private/Get-ParameterSetInUse.ps1 @@ -0,0 +1,27 @@ +Function Get-ParameterSetInUse { +# get parameter set name to be used, based on parameters hash passed + [cmdletbinding()] + param( + # Supply the script info object, output of Get-Command -Name .ps1 + [System.Management.Automation.ExternalScriptInfo]$ScriptInfo, + + # hashtable of all the parameters to be passed to the DeploymentScript + [hashtable]$ParameterHash + ) + + $Metadata = [System.Management.Automation.CommandMetadata]::New($ScriptInfo) + $CmdletBinding = [System.Management.Automation.ProxyCommand]::GetCmdletBindingAttribute($Metadata) + $Parameters = [System.Management.Automation.ProxyCommand]::GetParamBlock($Metadata) + + $FunctionBody = @" + $CmdletBinding + param( + $Parameters + ) + return `$PSCmdlet.ParameterSetName +"@ + + $DummyFunction = [scriptblock]::Create($FunctionBody) + + & $DummyFunction @ParameterHash +} \ No newline at end of file diff --git a/PSDeploy/Public/Invoke-PSDeploy.ps1 b/PSDeploy/Public/Invoke-PSDeploy.ps1 index e3e9d56..dd9b2b5 100644 --- a/PSDeploy/Public/Invoke-PSDeploy.ps1 +++ b/PSDeploy/Public/Invoke-PSDeploy.ps1 @@ -215,7 +215,25 @@ # First, get the script, parse out parameters, restrict splatting to valid params $DeploymentScript = $DeploymentScripts.$Type - $ValidParameters = Get-ParameterName -Command $DeploymentScript + + # Below has to be changed to factor in different paramete sets + $ScriptInfo = Get-Command -Name $DeploymentScript + $ScriptParameterSetsName = @($ScriptInfo.ParameterSets.Name) + + # get the valid parameters based on the parameters specified within the WithOptions block + if (($ScriptParameterSetsName.Count -eq 1) -and + ($ScriptParameterSetsName -contains '__AllParameterSets')) + { + # this infers that no parameter sets + $ValidParameters = Get-ParameterName -Command $DeploymentScript + } + else + { + # Parameter sets defined, now figure out which parameter set is used. + $ParameterSetUsed = Get-ParameterSetinUse -ScriptInfo $ScriptInfo -ParameterHash $Deployment.DeploymentOptions + $ValidParameters = Get-ParameterName -command $DeploymentScript -parameterset $ParameterSetUsed + } + $FilteredOptions = @{} foreach($key in $Deployment.DeploymentOptions.Keys)