Product: PowerShell Universal
Version: 2.10.2
Hey @adam,
We are running a dashboard with a custom PS module with a parameter for Environment
. When we try to run the commands inside the dashboard, we are receiving the following error:
Cannot validate argument on parameter 'Environment'. Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
at System.Management.Automation.PowerShell.Invoke()
at UniversalDashboard.Execution.PowerShellExecutionService.ExecuteEndpoint(ExecutionContext context, AbstractEndpoint endpoint, List`1 nonTerminatingErrors) in D:\a\universal\universal\src\UniversalDashboard\Execution\PowerShellEx
We are using an IValidateSetValuesGenerator
class to dynamically get [ValidateSet]
values.
using namespace System.Management.Automation
class Environment : IValidateSetValuesGenerator {
[string[]] GetValidValues() {
$Configuration = Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Configuration.json') |ConvertFrom-Json
$Values = foreach ($Environment in $Configuration.Environment.PSObject.Properties.Name) {
$Environment
}
return $Values
}
}
Thanks!