Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Created October 20, 2016 17:38
Show Gist options
  • Save sheldonhull/dbbc8356028264047fd742b56c5ee27e to your computer and use it in GitHub Desktop.
Save sheldonhull/dbbc8356028264047fd742b56c5ee27e to your computer and use it in GitHub Desktop.
Basic Setting of Variables from JSON object via powershell that's dynamic
#get json content (should not be nested, just flat file of variables)
$json = Get-Content -Raw -Path ([io.path]::Combine($Path,"settings.json")) -force | ConvertFrom-Json
#get list of variable in collection available
[string[]]$variables = ($json | get-member -Name * -MemberType NoteProperty).Name
#iterate through each variable name and get the value from the json object
foreach ($v in $variables)
{
Set-Variable -name $v -value ($json.$v) -Force -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment