I am getting a list of values from the command line in format of key=val key=val, after splitting them down and then into key and value, I want to set an environment variable using the key.
I have tried the following code ($sstr is being set from arguments, but I have hard coded it to simplify the code), but I am getting 'unexpected token' error:
$retrievedVal = "key1=val1 key2=val2"
# Split the string, with space being the delimiter, leaving key=value
$sstr = $retrievedVal .split( " " )
foreach ( $var in $sstr )
{
$keyvalueList = $var.split( "=" )
$env:($keyvalueList[0]) = "Test"
}
Any suggestions to where I have gone wrong would be greatly appreciated :)