Skip to content

Commit

Permalink
Fix for using parameter sets in PSDeployScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterPOSH committed Nov 28, 2016
1 parent 7e4206a commit 3f1fb77
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
27 changes: 27 additions & 0 deletions PSDeploy/Private/Get-ParameterSetInUse.ps1
Original file line number Diff line number Diff line change
@@ -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 <DeploymentScript>.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
}
20 changes: 19 additions & 1 deletion PSDeploy/Public/Invoke-PSDeploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3f1fb77

Please sign in to comment.