Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving and loading settings in yaml files #4

Closed
gitfvb opened this issue Nov 2, 2023 · 2 comments
Closed

Saving and loading settings in yaml files #4

gitfvb opened this issue Nov 2, 2023 · 2 comments

Comments

@gitfvb
Copy link
Contributor

gitfvb commented Nov 2, 2023

This looks promising: https://github.com/cloudbase/powershell-yaml

$settings | ConvertTo-Yaml | Set-Content -path "settings.yaml" -Encoding UTF8 
$s = get-content -Path settings.yaml -Encoding UTF8 -Raw | ConvertFrom-Yaml

But the second command gives us a hashtable back instead of a pscustomobject, which could also be handled, but needs a second thought.

Good hints on the second topic: https://stackoverflow.com/questions/72218329/unable-to-convert-yaml-to-powershell-object

So this should work

[pscustomobject]$os_list = (ConvertFrom-Yaml -yaml (get-content -Raw C:\Powershell\TestCSVs\variables.stg.yml))
[pscustomobject]$os_list = ConvertTo-Yaml $os_list -JsonCompatible

or this, too

$documentWithVariables = Get-Content -Path ..\variables.stg.yml -Raw |ConvertFrom-Yaml 
$oData = [PSCustomObject]$documentWithVariables.variables

More notes about using comments
aaubry/YamlDotNet#534

Use this in vscode
https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml

Link these dependencies directly
Package: https://github.com/aaubry/YamlDotNet
Module: https://github.com/cloudbase/powershell-yaml

gitfvb added a commit that referenced this issue Nov 2, 2023
The powershell-yaml always generates hashtable instead of PSCustomObject. With another transformation in json and loading it then, it works fine.
@gitfvb
Copy link
Contributor Author

gitfvb commented Nov 3, 2023

Looks good so far. Currently in testing phase.

@gitfvb
Copy link
Contributor Author

gitfvb commented Nov 21, 2023

This is published now with 0.2.0

@gitfvb gitfvb closed this as completed Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant