I have script which accepts two parameters, a string arg1
and a hashtable arg2
:
Script.ps1
Param(
[string]$arg1,
[hashtable]$arg2,
)
Write-Host "@$(ConvertTo-Json $arg2)"
How can I pass a dictionary from powershell into this script, by calling it such that it runs in a separate process.
Call.ps1
$d = @{a="bla"}
$s = "@$((ConvertTo-Json $a -Compress) -replace ':','=')"
powershell -File Script.ps1 "-arg2 $s" # We need another process (no access to the variables in this script)
I don't know what I am doing wrong (see this question), but this does not work. Or is there another