Dynamic params - Invoking script from admin page

Dynamic params - Invoking script from admin page

avatar
Product: PowerShell Universal
Version: 1.4.6


Is anyone doing anything with dynamic params?

For instance I have an item in a paramset that if you pick it from the dropdown I would like to require another param to set. I know you could do this with pages but was wondering if you could do it from admin page when invoking the script?

[CmdletBinding()]
param(
    [Parameter(Mandatory = $false, HelpMessage = 'Select that actions you want to perform')]
    [ValidateSet('retentionpolicy-update', 'emailaddresses-update')]
    [String[]]
    $Actions
)

DynamicParam {
    $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary

    if ($Actions -contains 'emailaddresses-update') {
        $paramName = 'NewEmailAddress'
        $attributes = New-Object System.Management.Automation.ParameterAttribute
        $attributes.Mandatory = $true
        $dynParam = New-Object System.Management.Automation.RuntimeDefinedParameter($paramName, [string], $attributes)
        $paramDictionary.Add($paramName, $dynParam)
    }
    $paramDictionary
}

process {
    # Access the $NewEmailAddress parameter here if 'emailaddresses-update' is in $Actions
    if ($Actions -contains 'emailaddresses-update') {
        Write-Host "New Email Address: $($NewEmailAddress)"
    }


All Comments (3)

avatar

Were you ever able to accomplish this? There’s another post on the forum with a similar issue, and my experience seems to be the same as yours.
It may be due to my lack of familiarity with the DynamicParam block, I’ll have to do some testing outside of PowerShell Universal to be sure.

avatar

Looks like this will be in v5

github.com/ironmansoftware/issues

avatar
Were you ever able to accomplish this? There’s another post on th

I was not able to get this to work. Looking forward to this in version 5