Skip to content

Instantly share code, notes, and snippets.

@TomasBouda
Created July 23, 2019 08:05
Show Gist options
  • Save TomasBouda/ac139d4e6a5c7f5dd69a4f773920906e to your computer and use it in GitHub Desktop.
Save TomasBouda/ac139d4e6a5c7f5dd69a4f773920906e to your computer and use it in GitHub Desktop.
Dynamicaly create powershell variable
# config.json
#{
# "variables": [
# {
# "name": "basePath",
# "value": "C:\\inetpub\\approot"
# }
# ],
# "test": "$basePath\\test"
#}
#-----------
$config = Get-Content $jsonConfigPath | ConvertFrom-Json
foreach($var in $config.variables){
New-Variable -Name $var.name -Value $var.value -Force -Option ReadOnly
}
$pathToTest = $ExecutionContext.InvokeCommand.ExpandString($config.test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment