Comments (1)
This turned out to be more complicated than expected. The implementation of -NoValidateSet
added in ed54f45 was easy enough, but it exposed a deeper problem with using -AsCustomObject
.
Because of the way PowerShell generates a Script Method, my default template will always fail with these methods.
The reason is that the param()
block specified in a Script Method is not implemented as such; instead each parameter is created as a local variable and its value is set to whatever the parameter supplied to the method is. This is why the [ValidateSet()]
attributes fail too, so it's probably the same logic as a closure or perhaps internally it's just creating a closure.
But what this means is that there's no way inside of the method to programmatically determine what the parameters are; $MyInvocation.MyCommand
has an empty .Parameters
set.. because there are no parameters, just local variables. This means using $PSBoundParameters
and even $args
fails.
Because of that, there's no good way to use a templating system like this to dynamically build the [hashtable]
that needs to be provided to Invoke-DscResource
, because you'd need to know all the parameter names in advance or tease them out from the local variables.
As a result, the entire concept of using -AsCustomObject
for what we're doing here is probably useless 99% of the time.
The one instance where I could see it being useful is when you have a very specific custom template definition that knows the parameter names already, so it doesn't need to use dynamic discovery of them. It might supply values for nearly all of them and maybe it uses a few dynamically by direct name.
Behavior Changes
-NoValidateSet
is available for all parameter sets so it can be used for the other modes (not using a custom object) if that's desired.- When
-AsCustomObject
is specified,-NoValidateSet
is automatically enabled, but it can be overridden with-NoValidateSet:$false
if there's some reason for that. - When
-AsCustomObject
is specified and the default template is used, the call is allowed, but a warning is emitted explaining that the resulting methods will not work.
from idempotion.
Related Issues (16)
- Verbose output is longer than it should be HOT 1
- Fix single quote escaping HOT 1
- Investigate use of Security.SecurityCritical() attribute HOT 1
- In mocked WhatIf support, the action and target are reversed HOT 1
- Add InvertTest parameter
- Add option to convert [bool] properties to [Switch] parameters
- Support ExcludeProperty and ExcludeMandatory parameters HOT 3
- The snippet for putting parameters into a hashtable is subtly mangling arrays
- Parameter discovery snippet pollutes error reporting
- Parameterization snippet should be separated out to a function HOT 1
- Gracefully handle multiple module versions
- Tests are needed for Convert-DscResourceToCommand
- Help Wanted
- Examples needed
- The -Force parameter doesn't properly remove the existing module
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 idempotion.