Comments (5)
Thank you for your help and information! It is greatly appreciated!
from powershell.
The immediate problem is that -String2
and -Type
cannot be combined unambiguously, causing parameter binding to stop right there - your DynamicParam
block is never called.
To at least eliminate the "parameter set cannot be resolved error", comment out the [Parameter()]
attribute that contains ParameterSetName = 'DynamicA-String2'
that decorates the $String2
parameter.
It looks like you can greatly reduce the number of parameter sets, which will likely also solve your problem.
from powershell.
In other words, dynamic parameters cannot be used to make a parameter set unambiguous, requiring the static parameters to unambiguously select a parameter set.
I was able to change the dynamic parameter to not set the ParameterSetName, which allowed for the reduction of parameter sets to resolve. However, I want to know if this was a bug or if it was by design. It sounds like it is by design.
from powershell.
In other words, dynamic parameters cannot be used to make a parameter set unambiguous, requiring the static parameters to unambiguously select a parameter set.
That's a great summary. Yes, any given static parameters must resolve unambiguously to a parameter set first.
While I cannot speak in any official capacity, I do think that this is by design, given the stages of parameter binding described by a team member in #14701 (comment) - also see the clarification in #14701 (comment).
Here's what I think is a minimal example:
function Test-AmbiguousParameter {
[CmdletBinding(DefaultParameterSetName = 'Default')]
param (
[Parameter(Mandatory = $true, ParameterSetName = 'Default')]
$A,
[Parameter(Mandatory = $false, ParameterSetName = 'Other')]
$B
)
DynamicParam {
Write-Verbose -Verbose HERE
}
process {
Write-Output $PSCmdlet.ParameterSetName
}
}
Test-AmbiguousParameter -a 1 -b 2
predictably yields the "parameter set cannot be resolved" error and never prints the VERBOSE: HERE
message, implying that the DynamicParam
block is never invoked.
Contrast with Test-AmbiguousParameter -a 1
and Test-AmbiguousParameter -b 2
from powershell.
📣 Hey @netsec4u, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback
from powershell.
Related Issues (20)
- Commands candidates? HOT 5
- Docker connecting to Exchange PowerShell operations is extremely slow
- Incorrect output when calling PowerShell's Invoke function in C# HOT 1
- Restart-Computrr add proxyaccestype
- What programming guidelines are there for PowerShell against the AMSI threat vector? HOT 21
- Get-ADComputer doesn't return nTSecurityDescriptor content HOT 2
- update ::user privilege to access powershell HOT 9
- Out-File not reporting error on failure to write to UNC network path when stream is being repeatedly opened and closed. HOT 2
- When "Controlled Folder Access" is enabled, PowerShell 7.4.2 is so Slow it's Unusable HOT 5
- I want return an empty array in a function, but it return a null value. HOT 13
- Please support Ubuntu 24.04 as soon as possible,thku HOT 4
- ForEach-Object -Parallel / Start-ThreadJob don't honor unsilencing of silent-by-default streams via common parameters HOT 6
- Add support for Enterprise signed scripts HOT 7
- No runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property HOT 11
- [Regression in 7.4.2] Statement in finally block stop working when ctrl-c is pressed that stops script running in the try block
- PowerShell extended property `BaseName` for `DirectoryInfo` is inconsistent when there is an `extension` HOT 34
- `$PSScriptRoot` unpopulated when script missing the `.ps1` file extension HOT 10
- `-LiteralPath` still interprets `~` HOT 12
- Invoke-Command does not support -Startuptype AutomaticDelayedStart HOT 3
- Default case in Switch not called when variable is in an undefined state HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powershell.