You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can PSF be used to read settings from e.g., a config.json file ? The use-case is that I want to provide a configuration file to my automation script. I need a module that simplifies reading the config file, checking the config value, validating it, throwing an error if it is invalid, or provide a default value if the value is missing. It looks like PSF can do all of that, but I have not found a simple example of how I read a value in from a file.
The text was updated successfully, but these errors were encountered:
Hi @danielniccoli ,
Yeah, I really need to make my docs more discoverable. Also need to add some videos for it.
So, to read a configuration file, there are different "schemata" - definitions, on how a config file is supposed to look like. If the builtin ones don't work for you, you can define your own schema (not for the faint of heart, but possible).
Here's the docs for the one you'll find most useful, given your description. It understands both json and psd1 files, whatever works better for you :)
Note: The path can also be a weblink or blank json string.
Now, to validate & default-value settings, you need to define these settings via Set-PSFConfig. While config initialization was implemented with modules in mind, that is in no way a requirement. Here's an example file from PSFramework itself.
Validation: What validation rule to apply to the setting. Will type-convert input if technically legal but in the wrong datatype. If the builtin validation rules are not enough, you can define your own.
Can PSF be used to read settings from e.g., a
config.json
file ? The use-case is that I want to provide a configuration file to my automation script. I need a module that simplifies reading the config file, checking the config value, validating it, throwing an error if it is invalid, or provide a default value if the value is missing. It looks like PSF can do all of that, but I have not found a simple example of how I read a value in from a file.The text was updated successfully, but these errors were encountered: