AL/Get-EnvironmentKeyValue.ps1
<#
.Synopsis Retrieves a value from the settings.json .Description Retrieves the value for the speficied key from the project's settings.json .Parameter SourcePath Path to the current project .Parameter KeyName Name of the key .Example $value = Get-EnvironmentKeyValue -SourcePath "C:\Install" -KeyName "locale" #> function Get-EnvironmentKeyValue { Param( [Parameter(Mandatory=$false)] [string]$SourcePath = (Get-Location), [Parameter(Mandatory=$true)] [string]$KeyName ) if (!(Test-Path (Join-Path $SourcePath 'settings.json'))) { return '' } $JsonContent = Get-Content (Join-Path $SourcePath 'settings.json') -Raw $Json = ConvertFrom-Json $JsonContent if ($null -ne $Json.PSObject.Properties.Item($KeyName)) { try { $Json.PSObject.Properties.Item($KeyName).Value } catch { throw "Could not find value for $KeyName in settings.json" } } else { return '' } } Export-ModuleMember Get-EnvironmentKeyValue |