title: How can a Windows PowerShell script pass its parameters through to another script invocation?
body: <p>In short, I'm just looking for the PowerShell equivalent of how a batch file can call a script with the same parameters...</p>
  
  <pre><code>"%~dpnx0" %*
  </code></pre>
  
  <p>...where <code>"%~dpnx0"</code> expands to the absolute path of the script and <code>%*</code> is expanded to the list of parameters.  Is there an easy way to replicate <code>%*</code>?  Or, at least, a way that works?</p>
  
  <p>I have a PowerShell script that uses the <code>System.Data.OleDb</code> namespace to read data from an <code>Excel</code> workbook.  Because there is no 64-bit implementation of the Microsoft Jet provider, the script needs to be run from a 32-bit PowerShell session.  Rather than simply having the script fail with an error message if it's run from a 64-bit session, I'd like to have the 64-bit session invoke the script in and retrieve the results from a 32-bit session.  I found that this can be done using the <a href="http://technet.microsoft.com/library/dd347692.aspx" rel="nofollow noreferrer"><code>Start-Job</code> cmdlet</a> with the <code>-RunAs32</code> switch, however I'm having trouble providing a value for the <code>-ArgumentList</code> parameter.</p>
  
  <p>I came up with the following to search for whichever script parameters have values and build a command line out of them:</p>
  
  <pre><code>function GetValueText([Object] $value)
  {
      [String] $text = if ($value -eq $null) {
          '$null';
      } elseif ($value -is [String]) {
          "'$value'";
      } elseif ($value -is [Array]) {
          '@({0})' -f (($value | ForEach-Object { GetValueText $_ }) -join ', ');
      } else {
          "$value";
      }
  
      return $text;
  }
  
  if ([IntPtr]::Size -gt 4)
  {
      [String] $scriptPath = $MyInvocation.MyCommand.Path;
      [String[]] $parameters = @(
          $MyInvocation.MyCommand.Parameters.Keys `
          | ForEach-Object {
              [Object] $parameterValue = Get-Variable -Name $_ -ValueOnly;
  
              if ($parameterValue -ne $null)
              {
                  [String] $parameterValueText = GetValueText $parameterValue;
  
                  '-{0}' -f $_;
                  $parameterValueText;
              }
          }
      );
      [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList $parameters;
      [Object[]] $data = $job | Wait-Job | Receive-Job;
  
      $data;
  }
  else
  {
      # Retrieve data...
  }
  </code></pre>
  
  <p>When it gets to the <code>Start-Job</code> line it generates an error with message <code>"Cannot convert value "-Argument1" to type "System.Int32[]""</code>.  <code>-Argument1</code> is the script's first parameter and is of type <code>[Int32[]]</code>, so does this mean that <code>-ArgumentList</code> only works with positional and not named parameters?</p>
  
  <p>I've also tried simplifying it to...</p>
  
  <pre><code>param(
      [String] $stringArg,
      [Int32] $int32Arg
  )
  
  $PSBoundParameters;
  
  if ([IntPtr]::Size -gt 4)
  {
      [String] $scriptPath = $MyInvocation.MyCommand.Path;
      [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList @PSBoundParameters;
  
      $job | Wait-Job | Receive-Job;
  }
  else
  {
      Get-Date;
  }
  </code></pre>
  
  <p>...but when I run <code>.\Test.ps1 'string' 12345</code> from a 64-bit session, it displays...</p>
  
  <pre><code>Key                                                         Value
  ---                                                         -----
  stringArg                                                   string
  int32Arg                                                    12345
  Start-Job : Missing an argument for parameter 'ArgumentList'. Specify a parameter of type 'System.Object[]' and try again.
  At X:\Test.ps1:11 char:72
  +     [Object] $job = Start-Job -FilePath $scriptPath -RunAs32 -ArgumentList &lt;&lt;&lt;&lt;  @PSBoundParameters;
      + CategoryInfo          : InvalidArgument: (:) [Start-Job], ParameterBindingException
      + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.StartJobCommand
  </code></pre>
  
  <p>...so <code>@PSBoundParameters</code> seems to evaluate to <code>$null</code>.  I'm not sure why this isn't working or what else to try.</p>