mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
win: handle non string as an environment value (#37215)
* win: handle non string as an environment value * Changed powershell environment handler to use .net function instead for special chars
This commit is contained in:
parent
58261a42e9
commit
708869edd6
2 changed files with 30 additions and 1 deletions
|
@ -162,7 +162,10 @@ Function Run($payload) {
|
|||
$ps.AddStatement().AddScript("Function Write-Host(`$msg){ Write-Output `$msg }") | Out-Null
|
||||
|
||||
ForEach ($env_kv in $payload.environment.GetEnumerator()) {
|
||||
$escaped_env_set = "`$env:{0} = '{1}'" -f $env_kv.Key,$env_kv.Value.Replace("'","''")
|
||||
# need to escape ' in both the key and value
|
||||
$env_key = $env_kv.Key.ToString().Replace("'", "''")
|
||||
$env_value = $env_kv.Value.ToString().Replace("'", "''")
|
||||
$escaped_env_set = "[System.Environment]::SetEnvironmentVariable('{0}', '{1}')" -f $env_key, $env_value
|
||||
$ps.AddStatement().AddScript($escaped_env_set) | Out-Null
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue