title: Powershell scripting : Why is this function not able to access a global variable
body: <p>i have a script, let's say script1 that calls a function abc from script2.
  Below is script2 :-</p>
  <pre><code>$Global:splat2 
  function xyz ()
  {
      Write-Host &quot;in xyz&quot;
      Write-Host &quot;$Global:splat2&quot;
  }
  function abc ([System.Collections.ArrayList] $splat)
  {
      $Global:splat2 = $splat
      Write-Host &quot;in abc&quot;
      Write-Host &quot;$Global:splat2&quot;
      $func = (Get-Command -Type Function xyz)
      $wholeFuncDef = 'Function ' + $func.Name + &quot; {`n&quot; + $func.Definition + &quot;`n}&quot;
  
      Start-Process powershell -args '-noprofile', '-noexit', '-EncodedCommand', `([Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes(&quot;$wholeFuncDef; xyz&quot;)))
      
  }
  </code></pre>
  <p>The function abc is called from script 1 (some value was assigned to $splat):</p>
  <pre><code>abc $splat
  </code></pre>
  <p>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.</p>