i have a script, let's say script1 that calls a function abc from script2. Below is script2 :-
$Global:splat2
function xyz ()
{
Write-Host "in xyz"
Write-Host "$Global:splat2"
}
function abc ([System.Collections.ArrayList] $splat)
{
$Global:splat2 = $splat
Write-Host "in abc"
Write-Host "$Global:splat2"
$func = (Get-Command -Type Function xyz)
$wholeFuncDef = 'Function ' + $func.Name + " {`n" + $func.Definition + "`n}"
Start-Process powershell -args '-noprofile', '-noexit', '-EncodedCommand', `([Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes("$wholeFuncDef; xyz")))
}
The function abc is called from script 1 (some value was assigned to $splat):
abc $splat
The problem is that only function abc prints the value for $splat2 while as in function xyz, $splat2 is empty. I was expecting that function xyz should also have the value for $splat2 since it's a global variable.